【问题标题】:Change title background color or making it transparent : android [duplicate]更改标题背景颜色或使其透明:android [重复]
【发布时间】:2018-05-04 06:00:06
【问题描述】:

如何更改标题栏的 bgcolor。默认情况下为其分配白色,因此电池使用情况、时间和通知图标不可见。

查看此图片链接了解问题描述:

screenshot

我已将图像设置为相对布局:

android:background="@drawable/img_bg"

并将 NoActionBar 主题应用于活动

<activity 
   android:name=".activity.LoginActivity" 
   android:theme="@style/AppTheme.NoActionBar">
</activity>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

【问题讨论】:

  • 转到 styles.xml 文件检查 AppTheme colorPrimaryDark 是否被提及。将该颜色更改为 #000000FF 以获得透明背景。
  • 试过了..没用。

标签: android


【解决方案1】:

更改窗口标题栏颜色:

Window window = activity.getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.setStatusBarColor(ContextCompat.getColor(activity, R.color.yourColor));
        }

对于 api

<resources>
    <style name="AppTheme" parent="android:Theme.Material">
        <!-- Customize your theme using Material Design here. -->
        <!-- Title Bar color here -->
        <item name="android:colorPrimary">#YOUR_COLOR_HERE</item>
        <!-- Background color here -->
        <item name="android:windowBackground">#YOUR_COLOR_HERE</item>
    </style>
</resources>

【讨论】:

  • 感谢@Shiva 成功了 :)
  • 但它只适用于大于 21 的 Api 级别。
  • 请检查编辑后的答案。
  • android:Theme.Material 需要 API 级别 21(当前最低为 16).. 我猜是 api>21
【解决方案2】:

试试这个。

<style name="AppTheme" parent="AppTheme.Base">
        <item name="android:windowTranslucentStatus">true</item>
</style>

【讨论】:

    【解决方案3】:

    试试这个(它只会改变你的标题栏颜色):

     <style name="AppTheme.NoActionBar">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
            <item name="colorPrimaryDark">@color/colorXYZ</item>
        </style>
    

    【讨论】:

    • 试过..还是一样
    猜你喜欢
    • 2013-04-17
    • 1970-01-01
    • 2017-06-06
    • 1970-01-01
    • 1970-01-01
    • 2014-07-15
    • 2015-01-07
    • 2012-09-10
    • 2014-07-12
    相关资源
    最近更新 更多