我有一个自定义警告对话框,其中我设置了一个列表视图,其背景为白色。
但是我得到了这样的观点。
这是适合整个屏幕的屏幕截图。
Dialog d = new Dialog(context,android.R.style.Theme_Translucent_NoTitleBar);
CustomDialogListAdapter customDialogAdapter;
ListView customList = new ListView(context);
customList.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
customList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
customDialogAdapter = new CustomDialogListAdapter(context,PaymentInfo.creditCardTypes, type);
customList.setAdapter(customDialogAdapter);
customList.setBackgroundColor(Color.WHITE);
d.setContentView(customList);
d.show();
提前致谢..!
答案 0 :(得分:7)
Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext,android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.custom_dialog);
dialog.show();
上面的代码将生成一个透明的对话框。因此,列表视图背景将是对话框的唯一背景。
答案 1 :(得分:1)
AlertDialog.Builder screenDialog = new AlertDialog.Builder(AndroidCaptureScreen.this);
screenDialog.setTitle("Captured Screen");
TextView TextOut = new TextView(AndroidCaptureScreen.this);
TextOut.setText(EditTextIn.getText().toString());
LayoutParams textOutLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
TextOut.setLayoutParams(textOutLayoutParams);
ImageView bmImage = new ImageView(AndroidCaptureScreen.this);
bmImage.setImageBitmap(bmScreen);
LayoutParams bmImageLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
bmImage.setLayoutParams(bmImageLayoutParams);
LinearLayout dialogLayout = new LinearLayout(AndroidCaptureScreen.this);
dialogLayout.setOrientation(LinearLayout.VERTICAL);
dialogLayout.addView(TextOut);
dialogLayout.addView(bmImage);
screenDialog.setView(dialogLayout);
screenDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
// do something when the button is clicked
public void onClick(DialogInterface arg0, int arg1) {
}
});
screenDialog.show();
}
答案 2 :(得分:0)
获取父视图布局并设置其背景:)
答案 3 :(得分:0)
这将使其有效:
列表视图中的添加此
机器人:cachecolorhint = “#00000000”
答案 4 :(得分:0)
在我的情况下,我通过使用此代码片段得到了欲望输出:
Dialog dialog2 = new Dialog(Activity.this);
ListView modeList = new ListView(Activity.this);
AlertDialog.Builder builder = new AlertDialog.Builder(Activity.this);
String[] stringArray = new String[] { "No results" };
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(Activity.this, R.layout.list_main, R.id.item_subtitle, stringArray);
modeList.setAdapter(modeAdapter);
builder.setView(modeList);
dialog2 = builder.create();
dialog2.show();
在list_main.xml中,将背景颜色设置为白色:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="7dp"
android:background="#ffffff">
</LinearLayout>
对于自定义适配器:
builder.setTitle(" title");
MySimpleAdapter adapter = new MySimpleAdapter(Activity.this, data , R.layout.list_main,
new String[] { "name", "distance" ,"phone","web"},
new int[] { R.id.item_title, R.id.item_subtitle ,R.id.item_subtitle1 ,R.id.item_subtitle2});
modeList.setAdapter(adapter);