【问题标题】:How to set the background of the titlebar?如何设置标题栏的背景?
【发布时间】:2010-09-23 06:54:45
【问题描述】:

我已按照这个 SO 问题的说明进行操作:How to change the text on the action bar

我能够成功地创建自己的标题栏,但是当我将背景颜色应用到我的布局时,颜色不会跨越整个标题栏。 android 灰色背景色仍有残留。

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="400px" 
  android:layout_height="fill_parent"
  android:orientation="horizontal" android:background="@color/solid_blue">

<ImageView android:id="@+id/logo" 
            android:layout_width="57px" 
            android:layout_height="wrap_content"
            android:background="@drawable/icon">

</ImageView>

<TextView 

  android:id="@+id/myTitle" 
  android:text="StockDroid by" 
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent" 
  android:textColor="#FFFFFF"
   />
</LinearLayout>

【问题讨论】:

    标签: java android android-linearlayout titlebar


    【解决方案1】:

    剩下的东西在 link 本身作为 comment 人。

    编辑:

    您错过了设置窗口标题的自定义样式并通过活动的android:theme 属性将其设置在清单中的内容。

    您必须在 res/values/styles.xml 文件中创建这两种样式:

    <style name="MyTheme" parent="android:Theme">
            <item name="android:windowTitleSize">50px</item>
            <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground
            </item>
    
        </style>
    <style name="WindowTitleBackground" parent="android:WindowTitleBackground">
            <item name="android:background">@android:color/transparent
            </item>
        </style>
    

    那么你必须在你的清单中将你的风格设置为主题,就像:

    <activity android:name=".activity"
                android:label="@string/appname" android:theme="@style/MyTheme" />
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-02
      • 1970-01-01
      • 1970-01-01
      • 2015-05-03
      • 2018-10-05
      • 2012-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多