-3

I want to put the label of my app to the center. By default its aligned to the left.

Label is the word CAIN which is shown here,

Label is the word CAIN which is shown here.

How can I do that? Here is the code of AndroidManifest.xml :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.khurshidyakubov.cain">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"

    **android:label="@string/app_name"**

    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Sagar Zala
  • 4,854
  • 9
  • 34
  • 62

1 Answers1

0

Try this inside your MainActivity,

      ActionBar actionbar = getActionBar();
      TextView textview = new TextView(getApplicationContext());

      LayoutParams lps = new  RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 
      LayoutParams.WRAP_CONTENT); 

      textview.setLayoutParams(lps);

      textview.setText("CAIN");

      textview.setTextColor(Color.WHITE);
      textview.setGravity(Gravity.CENTER);
      textview.setTextSize(22);
      actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
      actionbar.setCustomView(textview);