我想显示一个对话框/弹出窗口,其中显示一条消息,显示"您确定要删除此条目吗?" 用一个按钮说"删除".当Delete被触摸时,应该删除该条目,否则什么都没有.
我为这些按钮编写了一个单击侦听器,但是如何调用对话框或弹出窗口及其功能?
我想稍微更改标准Android按钮的颜色,以便更好地匹配客户的品牌.
到目前为止,我发现这样做的最好方法是将Button'drawable'改为drawable,位于res/drawable/red_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/red_button_pressed" />
<item android:state_focused="true" android:drawable="@drawable/red_button_focus" />
<item android:drawable="@drawable/red_button_rest" />
</selector>
Run Code Online (Sandbox Code Playgroud)
但这样做需要我居然为每一个按钮,我想自定义三种不同的可绘制(一个用于按钮在休息,一个集中的时候,和一个按下时).这似乎比我需要的更复杂,更干燥.
我真正想做的就是对按钮应用某种颜色转换.是否有更简单的方法来改变按钮的颜色而不是我正在做的事情?
我想知道是否有人可以帮助我.我正在尝试创建自定义AlertDialog.为此,我在styles.xml中添加了以下代码行
<resources>
<style name="CustomAlertDialog" parent="android:Theme.Dialog.Alert">
<item name="android:windowBackground">@drawable/color_panel_background</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
以下是主要活动.
package com.customdialog;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
public class CustomDialog extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.setTheme(R.style.CustomAlertDialog);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("HELLO!");
builder .setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//MyActivity.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int …Run Code Online (Sandbox Code Playgroud) 我正在努力使这个AlertDialog的三个项目变绿.问题是目前警报后面出现绿色背景,其中两个项目不显示为绿色.我目前使用以下代码设置AlertDialog的样式:
final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.ListRow));
Run Code Online (Sandbox Code Playgroud)
在我的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>
Run Code Online (Sandbox Code Playgroud)

我有一个对话框,对我来说效果很好,但我想在此对话框中为两个按钮设置背景.它的结构非常复杂,所以我不想将它重写为自定义对话框.但在这种情况下,是否有可能设置背景(更具体地说,有没有办法将样式设置为正/负/中性按钮)?