Textview:使用对话框标题样式:@android:style/TextAppearance.DialogWindowTitle [英] Textview: using the dialog title style: @android:style/TextAppearance.DialogWindowTitle

查看:171
本文介绍了Textview:使用对话框标题样式:@android:style/TextAppearance.DialogWindowTitle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试构建自己的DialogFragment主题.

I am currently trying tu build my own DialogFragment theme.

我的要求之一是在标题的右侧使用一个图标.

One of my requirement is to use an icon at the right of the title.

第一个想法

只需使用:

this.getDialog().getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.dialog_title);

但是不幸的是,这行代码没有结果.

But unfortunately, this line of code has no result.

第二个想法

使用此textview提供我自己的布局-this.setContentView()-

Provinding my own layout -this.setContentView()- with this textview:

<TextView
    android:id="@+id/tvTitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="From XML"
    android:textAppearance="@android:style/TextAppearance.DialogWindowTitle" />

这行得通,因为我可以阅读文本,但仍使用默认的黑色字体书写.

This works, because I can read the text, but it still written in default black font.

我期望TextAppearance.DialogWindowTitle给我的文本一个标题外观(Holo中的蓝色字体大)

I was expecting TextAppearance.DialogWindowTitle to give my text a title appareance (blue in Holo with big font size)

有什么想法或建议吗?

编辑

这几乎达到了目的:

<style name="Dialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowTitleStyle">@style/MyOwnDialogTitle</item>
</style>

<style name="MyOwnDialogTitle">
    <item name="android:drawableRight">@drawable/MyRightImage</item>
</style>

但是android:drawableRight刚刚打破了标题布局:

but android:drawableRight just broke the title layout:

第二编辑

这好一点:

<style name="Dialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowTitleStyle">@style/MyOwnDialogTitle</item>
</style>

<style name="MyOwnDialogTitle">
    <item name="android:textAppearance">@android:style/TextAppearance.DialogWindowTitle</item>
    <item name="android:drawableRight">@drawable/icon</item>
</style>

推荐答案

也许您可以通过以下方式扩展默认样式:

Maybe you can extend the default style in this manner:

res/values/dialogstyles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Dialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowTitleStyle">@style/MyOwnDialogTitle</item>
    </style>
    <style name="MyOwnDialogTitle">
        <item name="android:drawableRight">@drawable/MyRightImage</item>
    </style>
</resources>

res/values-v11/dialogstyles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
     <style name="Dialog" parent="@android:style/Theme.Holo.Dialog">
          <item name="android:windowTitleStyle">@style/MyOwnDialogTitle</item>
     </style>
</resources>

并覆盖DialogFragment的onCreate:

And override your DialogFragment's onCreate:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(DialogFragment.STYLE_NORMAL, R.style.Dialog);
}

工作示例

Working Example

这篇关于Textview:使用对话框标题样式:@android:style/TextAppearance.DialogWindowTitle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆