Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将自定义操作栏中的文本视图水平居中_Android_Android Layout_Textview - Fatal编程技术网

Android 将自定义操作栏中的文本视图水平居中

Android 将自定义操作栏中的文本视图水平居中,android,android-layout,textview,Android,Android Layout,Textview,A想要创建中间有应用程序名称的自定义ActionBar,但它仍然向左对齐。下面是custom_actionbar.xml的xml 你能告诉我我做错了什么吗? 谢谢将TextViews宽度更改为match\u parent并应用android:gravity=“center\u horizontal”将TextViews宽度更改为match\u parent并应用android:gravity=“center\u horizontal”使用android支持工具栏定制actionbar 使用此链接

A想要创建中间有应用程序名称的自定义ActionBar,但它仍然向左对齐。下面是custom_actionbar.xml的xml

你能告诉我我做错了什么吗?
谢谢

TextView
s宽度更改为
match\u parent
并应用
android:gravity=“center\u horizontal”

TextView
s宽度更改为
match\u parent
并应用
android:gravity=“center\u horizontal”

使用android支持
工具栏
定制actionbar


使用此链接作为参考

使用android支持
工具栏
作为自定义操作栏


使用此链接作为参考

尝试使用线性布局,并删除此行android:layout\u centerInParent=“true”尝试使用线性布局,并删除此行android:layout\u centerInParent=“true”
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:background="@color/transparent">

        <TextView
            android:id="@+id/nav_bar_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@color/transparent"
            android:singleLine="true"
            android:textColor="@color/sue_green"
            android:text="@string/app_name"
            android:textAppearance="?android:attr/textAppearanceLarge">
        </TextView>

</RelativeLayout>
public class DeviceOverviewActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);

        setTheme(R.style.Theme_SUE);
        setContentView(R.layout.activity_device_overview);

        final ActionBar actionBar = getActionBar();
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayUseLogoEnabled(false);

        LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflator.inflate(R.layout.custom_actionbar, null);

        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(v);
    }
...
}