我想知道是否有一种简单的方法可以告诉Android始终使用自定义样式来显示Dialogs
。
使用主题和样式,您可以更改所有内容的外观,例如,在主题中定义主题时TextViews
使用以下代码.xml:
<item name="android:textViewStyle">@style/Blue.TextView</item>
在样式中定义 Blue.TextView.xml。
有没有办法也为Dialogs
做到这一点?
是的,有。 例如,
AlertDialog.Builder b = new AlertDialog.Builder(context, R.style.MyTheme);
或者,如果你使用的是DialogFragment
,只需调用 setStyle() 方法,
<style
name="Theme_Dialog_Translucent"
parent="android:Theme.Dialog">
<item
name="android:windowBackground">@null</item>
</style>
以下是工作代码:
Dialog mDialog = new Dialog(this,R.style.ThemeDialogCustom);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setCanceledOnTouchOutside(true); //But here It is not workin
mDialog.setContentView(R.layout.popup);