Android:自定义标题样式

发布于 2024-12-01 07:27:45 字数 1901 浏览 3 评论 0原文

我有一个带有图标化文本的列表活动,我给它一个自定义标题。这是我的custom_style.xml:

<resources>
    <style name="CustomWindowTitleBackground">
        <item name="android:background">#222222</item>
    </style>

    <style name="CustomTheme" parent="android:Theme">
        <item name="android:windowTitleSize">50dip</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
    </style> 
</resources>

这是标题的布局,window_title.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"

    android:layout_height="50dip"
    android:gravity="center_vertical"
    android:paddingLeft="10dip"
    android:background="#222222">

    <ImageView
        android:id="@+id/header"
        android:src="@drawable/header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

我在onCreate中设置了新的标题样式:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    // if it wasn't a listactivity, here I'd use
    // setContentView(R.layout.main);

    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);

    browseToRoot();
}

我的问题是样式化的标题栏以正确的大小和正确的背景颜色显示(取自custom_style.xml)。 xml) 但 window_title.xml 中的所有内容都将被忽略。列表适配器的其余部分仍然可以正常工作。在一个非常类似的问题中:带有图像的自定义标题它说 setFeatureInt 必须出现在之前 super.onCreate 但无论哪种方式我的结果是相同的。

我尝试用一​​个漂亮的简单文本视图替换图像视图,但整个 window_title.xml 似乎被忽略。有什么想法我哪里出错了吗?非常感谢,巴兹。

I have a listactivity with iconified text which I'm giving a custom title. Here's my custom_style.xml:

<resources>
    <style name="CustomWindowTitleBackground">
        <item name="android:background">#222222</item>
    </style>

    <style name="CustomTheme" parent="android:Theme">
        <item name="android:windowTitleSize">50dip</item>
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
    </style> 
</resources>

Here's the layout for the title, window_title.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"

    android:layout_height="50dip"
    android:gravity="center_vertical"
    android:paddingLeft="10dip"
    android:background="#222222">

    <ImageView
        android:id="@+id/header"
        android:src="@drawable/header"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

I set the new title style in onCreate:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    // if it wasn't a listactivity, here I'd use
    // setContentView(R.layout.main);

    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);

    browseToRoot();
}

My problem is that the styled title bar appears at the correct size and with the correct background colour (taken from custom_style.xml) but eveything in window_title.xml is ignored. The rest of the listadapter still works fine. In a very similar question here: Custom title with image it says setFeatureInt must come before super.onCreate but either way my result is the same.

I've tried replacing the imageview with a nice simple textview, but the entire window_title.xml seems to be ignored. Any ideas where I'm going wrong? Many thanks, Baz.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文