Android 6.0对话框文本不';不出现
我将手机更新为Android 6.0,对话框有以下两个问题: 1) 标题已显示,但消息不适用于警报对话框(已解决): 2) 此外,未显示自定义对话框片段的标题(未解决): 在棒棒糖或旧版本中没有这样的问题,只有在将我的手机升级到棉花糖后,问题才出现 如何解决这个问题Android 6.0对话框文本不';不出现,android,android-alertdialog,android-dialogfragment,android-dialog,android-6.0-marshmallow,Android,Android Alertdialog,Android Dialogfragment,Android Dialog,Android 6.0 Marshmallow,我将手机更新为Android 6.0,对话框有以下两个问题: 1) 标题已显示,但消息不适用于警报对话框(已解决): 2) 此外,未显示自定义对话框片段的标题(未解决): 在棒棒糖或旧版本中没有这样的问题,只有在将我的手机升级到棉花糖后,问题才出现 如何解决这个问题 new AlertDialog.Builder(context) .setTitle("Delete entry") .setMessage("Are you sure you want to delete this
new AlertDialog.Builder(context)
.setTitle("Delete entry")
.setMessage("Are you sure you want to delete this entry?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
希望这能帮助你
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.dialog_fire_missiles)
.setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
return builder.create();
}
一旦选中此选项,希望它能起作用……我怀疑您最终会在白色背景上显示白色文本!(从屏幕截图上看,(i)图标也没有很好地显示出来,这表明它的设计背景不是白色的
您可以使用构造函数
public AlertDialog.Builder(Context-Context,int-themeResId)
来确保使用特定的主题来设置对话框的样式,其中theme\u Material\u对话框可能就是您想要的。将构造函数与主题一起用于棒棒糖和较新的android版本:
黑暗主题
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(context);
}
对于轻主题
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Light_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(context);
}
在我的例子中,所有对话框的颜色都与字体相同(标题和消息)。我所做的是修改主题中的颜色属性。我将xml主题文件复制到“res/values-v22”中,并为棉花糖设置不同的颜色
<resources>
<style name="LywCompatTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:textColorPrimary">@android:color/tertiary_text_dark</item>
</style>
</resources>
@安卓:彩色/三级\u文本\u深色
或者仅用于对话框
<resources>
<style name="LywCompatTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:alertDialogTheme">@style/LywAlertDialogStyle</item>
</style>
<style name="LywAlertDialogStyle" parent="Base.Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">@color/lyw_secondary_text_color</item>
</style>
</resources>
@style/LywAlertDialogStyle
@颜色/lyw\U次要\U文本\U颜色
回答2)
,我们需要在onCreateDialog()之前调用setStyle()
,因为主题在onCreateDialog()中使用
只要把它放在你的基本主题样式标签内的样式文件中,你就可以开始了
<item name="android:alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert</item>
@style/Theme.AppCompat.Light.Dialog.Alert
我试图通过制作自己的样式来解决这个问题
对话框对象应该是这样的,指向该对话框的样式将写在下面
new AlertDialog.Builder(new ContextThemeWrapper(Context, R.style.Dialog))
.setTitle("Title")
.setMessage("Sample Message ...").show();
R.style.Dialog::
<style name="Dialog">
<item name="android:textColorPrimary">@color/primary_text</item>
<item name="android:textColor">@color/primary_color</item>
</style>
<color name="primary_text">#212121</color>
<color name="primary_color">#2196f3</color>
@颜色/主文本
@颜色/原色
颜色::
<style name="Dialog">
<item name="android:textColorPrimary">@color/primary_text</item>
<item name="android:textColor">@color/primary_color</item>
</style>
<color name="primary_text">#212121</color>
<color name="primary_color">#2196f3</color>
#212121
#2196f3
最后,输出应该是这样的
注意:“android:textColorPrimary”表示对话框设置消息,“android:textColor”表示对话框设置标题;我没有在我的对话框对象中使用setPositive和setNegative按钮和侦听器,但您可以在图片中看到它们,如果您愿意,您可以创建自己的对话框对象
可能您的主文本颜色与对话框背景颜色相同,在您使用styles.xml时(仅举一个例子):
我遇到了一些答案,它们说你应该在应用程序主题中使用以下内容:
<item name="android:alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert</item>
@style/Theme.AppCompat.Light.Dialog.Alert
虽然这是正确的,但它并不是在所有地方都适用于我。最终,我意识到在某些地方我使用的是常规的AlertDialog builder,而在其他地方我使用的是support builder。如果您使用的是support AlertDialog,请确保在主题中还包括以下内容:
<item name="alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert</item>
@style/Theme.AppCompat.Light.Dialog.Alert
使用对话框片段
时,您需要
添加样式
<style name="CustomDialog" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">false</item>
</style>
就这样 发布所有代码时,您没有调用show
。我已经编辑了代码where is dialog。show()可以给出一些屏幕截图,因为从纯代码问题中我们看到没有dialog.show。并提供更多的代码。我已经添加了一个屏幕截图,它正在为我工作…好的,我会再检查一次,然后返回给你…你的应用程序的目标api 23吗?它在我的应用程序中工作正常,我已经检查过,它做得很好。。。。。。。在android api 23(NEXUS 5最新更新为android Marshmello)中,标题未在6.0中设置。。。有什么线索吗?谢谢Alexandr。这对于AlertDialog.Builder案例来说非常有效。是否有任何方法可以应用自定义对话框(扩展对话框类而不是关于片段)案例。@jettimadhuChowdary,当您创建自定义对话框时,请使用Dialog=new CustomDialog(这是android.R.style.Theme\u Material\u Dialog\u alert)代码>如果有很多对话框,这不是一个好方法@Stephen answer是最好的解决方案。我认为这个解决方案比在我们想要创建AlertDialog
的任何地方检查和更改主题都要好。这个答案应该推到顶部。
<item name="android:alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert</item>
<item name="alertDialogTheme">@style/Theme.AppCompat.Light.Dialog.Alert</item>
<style name="CustomDialog" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">false</item>
</style>
public class CustomDialogFragment extends DialogFragment{
public int getTheme() {
return R.style.CustomDialogFragment;
}
.
.
.