我目前正在尝试建立自己的DialogFragment主题。
我的一个要求是在标题的右边使用图标。
First idea
简单地使用:
this.getDialog().getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.dialog_title);
但不幸的是,这行代码没有结果。
Second idea
我自己的布局-this.setContentView()-使用这个文本视图:
<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" />
这是可行的,因为我可以阅读文本,但它仍然以默认的黑色字体书写。
我原以为TextAppearance.DialogWindowTitle会给我的文本添加一个标题(蓝色全息,字体很大)
有什么想法或建议吗?
编辑
这几乎做到了这一点:
<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刚刚打破了标题布局:
第二次编辑
这个更好一点:
<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>
发布于 2013-01-30 08:51:43
也许你可以用这种方式扩展默认样式:
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>
并覆盖对话框片段的onCreate
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.Dialog);
}
发布于 2013-01-29 12:31:47
我正在寻找你的第一个要求。但是对于第二个要求,你为什么不试着用你的自定义样式来改变TextAppearance.DialogWindowTitle的颜色呢?
我刚刚查看了android资源,其中有如下样式:
<style name="DialogWindowTitle">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">@style/TextAppearance.DialogWindowTitle</item>
</style>
对于TextAppearance.DialogWindowTitle风格:
<style name="TextAppearance.DialogWindowTitle">
<item name="android:textSize">18sp</item>
<item name="android:textStyle">normal</item>
<item name="android:textColor">?textColorPrimary</item>
</style>
现在,您可以更改TextAppearance.DialogWindowTitle样式的颜色并随心所欲。
希望你明白我的意思。
请随时发表评论。
发布于 2013-01-30 20:43:10
你有没有尝试过在样式中使用@android:style/Theme.Holo.Light.Dialog
作为parent
?这将只适用于安卓3+,因为在较早的版本中没有主题全息,但你可以创建自己的看起来像它的安卓较低版本。
https://stackoverflow.com/questions/14492341
复制相似问题