我正在尝试将此AlertDialog的三个项目设为绿色。问题是目前警报后面出现绿色背景,其中两个项目不显示为绿色。我目前使用以下代码设置AlertDialog的样式:
final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.ListRow));
在我的styles.xml中,我有这种风格:
<style name="ListRow">
<item name="android:background">@color/forest_green</item>
<item name="android:textSize">18sp</item>
<item name="android:textColor">@color/dialog_text</item>
</style>
答案 0 :(得分:0)
您可以像这样以编程方式设置自定义视图..
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.dialog_layout, (ViewGroup) getCurrentFocus());
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialoglayout);
builder.show();
在绿色背景的布局中创建dialog_layout.xml。
答案 1 :(得分:0)
final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.ListRow));
builder.setIcon(android.R.drawable.ic_dialog_info).setTitle("welcome")
.setMessage("...")
.setPositiveButton("login", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
Intent intent = new Intent(HomeActivity.this, LoginActivity.class);
startActivity(intent);
}
}).setNegativeButton("register", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
Intent intent = new Intent(getApplicationContext(),RegisterActivity.class);
startActivity(intent);
}
}).show();
答案 2 :(得分:0)
将Theme.AppCompat.Dialog.Alert
作为父对象定义对话框样式:
<style name="AlertDialog" parent="Theme.AppCompat.Dialog.Alert">
<item name="android:background">@color/green</item>
...
</style>
答案 3 :(得分:0)
尝试一下:
final AlertDialog ad = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AppTheme)).create();
添加按钮;和
for (int i = 0; i < 2;i++) {
Button b = ad.getButton(i);
b.setBackgroundColor(color);
}
ad.show();
更改主题和颜色。
答案 4 :(得分:-1)
使用这样的styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AlertDialogCustom" parent="@android:style/AlertDialog">
<item name="android:textColor">#00FF00</item>
<item name="android:typeface">monospace</item>
<item name="android:textSize">10sp</item>
</style>