【问题标题】:How to set the title at center in android status bar如何在android状态栏的中心设置标题
【发布时间】:2016-04-24 12:18:05
【问题描述】:

我从 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这样的东西?

【问题讨论】:

标签: java android android-actionbar statusbar


【解决方案1】:

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

这绝对适合你

【讨论】:

  • 我不使用操作栏,只是一个状态栏
  • 据我所知,状态栏只不过是操作栏。两者具有相同的功能。在这里您还可以通过编辑主题来制作中心文本。您可以将ActionBarActivity 用作您的操作栏
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-28
  • 1970-01-01
  • 2014-09-23
  • 2016-03-06
相关资源
最近更新 更多