Search code examples
androidlayoutalignment

How to align title of Activity on center or anywhere in android?


((TextView)((FrameLayout)((LinearLayout)((ViewGroup)getWindow().getDecorView()).getChildAt(0)).getChildAt(0)).getChildAt(0)).setGravity(Gravity.CENTER);

I have used this above code for aligning my title of activity in center but it will gave me a error i.e. "FrameLayout cannot be resolved to a type" and if removed the FrameLayout then it will give me the same error in LinearLayout. I have also change the title bar through android.xml file by adding these line:

          <application  android:label="@string/app_name">
          <activity android:name=".OptionsmenuAct"
              android:label="@string/app_name"

              android:theme="@android:style/Theme.Translucent">

         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>

Now I am trying to align according to my need and also want to increase size of title text.

How can I do this plz help me............


Solution

  • You'll actually want to use a custom title view for this. Check out this question : how to set custom title bar TextView Value dynamically in android?