如何将标签放在中心?

时间:2018-07-19 05:13:17

标签: java android xml

我想将我的应用程序标签放在中间。默认情况下,其向左对齐。

标签是这里显示的CAIN一词,

Label is the word CAIN which is shown here

我该怎么做? 这是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>

1 个答案:

答案 0 :(得分:0)

在您的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);