gpt4 book ai didi

java - 如何设置android状态栏的标题居中

转载 作者:太空宇宙 更新时间:2023-11-04 12:41:05 24 4
gpt4 key购买 nike

我从 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>

我还更改了 string.xml 中状态栏的标题:

<resources>

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

如何将标题设置到状态栏的中心?我猜是类似gravity.center的东西?

最佳答案

试试这个:-
这里需要添加一个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;

custom_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>

这绝对适合你

关于java - 如何设置android状态栏的标题居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36822990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com