Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.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
Java 如何在android状态栏的中心设置标题_Java_Android_Android Actionbar_Statusbar - Fatal编程技术网

Java 如何在android状态栏的中心设置标题

Java 如何在android状态栏的中心设置标题,java,android,android-actionbar,statusbar,Java,Android,Android Actionbar,Statusbar,我从styles.xml更改了状态栏的颜色: <resources> <color name="custom_theme_color">#42A5F5</color> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme

我从styles.xml更改了状态栏的颜色:

<resources>

<color name="custom_theme_color">#42A5F5</color>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->

    <item name="colorPrimaryDark">@color/custom_theme_color</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

#42A5F5
@颜色/自定义主题颜色
@颜色/颜色重音
我还将状态栏的标题从string.xml更改为:

<resources>

<string name="app_name">Qu-easy</string>
<item name="colorPrimaryDark">@color/custom_theme_color</item>
</resources>

曲易
@颜色/自定义主题颜色
如何将标题设置为状态栏的中心? 我猜是像重心之类的东西?

试试这个:-
这里您需要添加一个xml文件
onCreate
方法中编写以下代码

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.custom_actionbar);
ActionBar.LayoutParams p = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
p.gravity = Gravity.CENTER;
自定义\u actionbar.xml布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="XYZ"
    android:textColor="#ffffff"
    android:id="@+id/mytext"
    android:textSize="30dp"
    android:textStyle="bold"/>

</LinearLayout>

这肯定对你有用

试试这个:-
这里您需要添加一个xml文件
onCreate
方法中编写以下代码

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.custom_actionbar);
ActionBar.LayoutParams p = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
p.gravity = Gravity.CENTER;
自定义\u actionbar.xml布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
android:gravity="center"
android:layout_gravity="center">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="XYZ"
    android:textColor="#ffffff"
    android:id="@+id/mytext"
    android:textSize="30dp"
    android:textStyle="bold"/>

</LinearLayout>


这肯定对你有用

制作自定义操作栏关于此和than cener标题参考此公认答案制作自定义操作栏关于此和than cener标题参考此公认答案我不使用操作栏,只是状态栏根据我的知识状态栏只是操作栏。两者具有相同的功能。在这里,您还可以通过编辑主题来制作中心文本。你可以为你的动作栏设置
ActionBarActivity
,我不使用动作栏,只是一个状态栏,根据我的知识状态栏就是动作栏。两者具有相同的功能。在这里,您还可以通过编辑主题来制作中心文本。您可以为您的操作栏设置
ActionBarActivity