采用主题/样式运行自定义对话框布局 [英] Run a custom Dialog layout using Theme/Style
问题描述
我需要使用唯一的主题/样式选项运行自定义对话框布局。由code运行自定义对话框布局是不是我的选择。我想,这应该是可以通过属性的平均值的Android:布局,机器人:dialogLayout,*机器人:dialogCustomTitleDecorLayout,*机器人:dialogTitleIconsDecorLayout,*安卓dialogTitleDecorLayout&LT ; BR />< BR />
在对话样式我的活动的onCreate负载布局:
I need to run a custom dialog layout using only theme/style options. Running custom Dialog layout by code is not an option for me. I think this should be possible by mean of attributes "android:layout", "android:dialogLayout", "*android:dialogCustomTitleDecorLayout", "*android:dialogTitleIconsDecorLayout", "*android:dialogTitleDecorLayout".<br/><br/>
My Activity onCreate load layout in a Dialog Style:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.MyDialog);
setContentView(R.layout.mydialog);
this.setTitle("A title");
}
风格的XML:
style xml:
<style name="MyDialog" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowTitleStyle">@style/MyDialog.WindowTitle</item>
<item name="android:layout">@layout/dialog_title</item>
<item name="android:dialogLayout">@layout/dialog_title</item>
<item name="*android:dialogCustomTitleDecorLayout">@layout/dialog_title</item>
<item name="*android:dialogTitleIconsDecorLayout">@layout/dialog_title</item>
<item name="*android:dialogTitleDecorLayout">@layout/dialog_title</item>
</style>
<style name="MyDialog.WindowTitle">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">@style/TextAppearance_WindowTitle</item>
</style>
<style name="TextAppearance_WindowTitle">
<item name="android:textSize">32sp</item>
<item name="android:textColor">@+color/verdeTI</item>
</style>
请注意标题的文本颜色是正确应用(@ +彩色/ verdeTI),所以我有信心级联样式是正确的,但它似乎没有任何的布局选项在所有的工作,因为我仍然能看到标准的对话框布局。我的dialog_title使用完全不同的ImageView用于分压器,这样我可以肯定它加载时。 自定义分隔仅仅是最主要的原因,因为我需要一个不同的布局。
Please, note that Text colour of the title is correctly applied (@+color/verdeTI) so I am confident the cascading styling is right but it seems none of the layout options work at all because I continue to see the standard Dialog Layout. My "dialog_title" use a completely different ImageView for divider so I can be sure when it is loaded. The custom divider is just the main reason because I need a different layout.
更新15/4/2014
某些样式属性,但不支持任何View元素,只能作为一个主题被应用。这些样式属性适用于整个窗口,而不是任何类型的视图。例如,样式属性主题可以隐藏应用程序标题,隐藏状态栏,或者改变窗口的背景。这些类型的样式属性不属于任何View对象。为了发现这些主题只有样式属性,查看为开头的窗口属性R.attr参考。例如,windowNoTitle和windowBackground的样式属性只有当风格为主题的活动或应用程序应用的是有效的。请参阅下一节,了解如何应用风格为主题。的
以窗口确定属性仅适用于主题不是样式。什么是关于*布局属性?当他们被应用?
推荐答案
您可以通过传递 THEMENAME
为参数
的构造
喜欢这种方式。
You can try by passing ThemeName
as argument
of constructor
like this way.
public class TestDialog extends Dialog{
public TestDialog(Context context) {
super(context, R.style.YourTheme);
// TODO Auto-generated constructor stub
}
}
添加窗口功能,如果你需要。
Add window feature if you require.
请该类对象的任何活动,所以你可以使用对话框属性。
Make object of this class in any Activity so you can use Dialog property.
: - 更多信息 http://stackoverflow.com/a/18224754/942224
我使用这种方式。所以它可能会帮助你。
i was using this way. so it may be help you.
这篇关于采用主题/样式运行自定义对话框布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!