java - 如何设置标题栏的背景?

标签 java android android-linearlayout titlebar

我已经按照这个 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>

最佳答案

剩下的东西在那上面 link本身作为 comment男人。

编辑:

您错过了为窗口标题设置自定义样式并通过 Activity 的 android:theme 属性在 list 中设置它的东西。

您必须在 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>

然后你必须在你的 list 中将你的风格设置为主题,就像:

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

希望对您有所帮助。

关于java - 如何设置标题栏的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3776026/

相关文章:

java - Struts 1 上的操作调用之前确认对话框

java - Android:位图到字节数组并返回:SkImageDecoder::Factory 返回 null

java - Java 中使用 Comparable<T> 时出现抽象类错误

java - BiFunction 引用可以传递给需要功能接口(interface)的方法吗?

java - 在 MySQL 表中存储多个用户日历

android - 我正在尝试设置一个带有背景图片和 slider 的 View

android - 根据单元格数量可变宽度的 GridView

android - 线性布局中心

java - 将 Object[] 从 HashMap 键集转换为 String[]?

安卓菜单图标大小