Android AlertDialog去除黑边白边自定义布局

LayoutInflater inflater = this.getLayoutInflater();
View view = inflater.inflate(R.layout.test_alertdialog_listview,null);
ListView lv = (ListView)view.findViewById(R.id.test_alertdialog_listview);
lv.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,datas));
lv.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
alertdialog.dismiss();
Toast.makeText(TestAndroid.this, datas[position], Toast.LENGTH_LONG).show();
}
});
alertdialog = new AlertDialog.Builder(this)
// .setView(view);
.setItems(datas, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.create();
// 在此使用setview方法可以设置布局文件和alertdialog四周边框的距离,可以消除黑边框
alertdialog.setView(view, 0, 0, 0, 0);
alertdialog.show();

 

你可能感兴趣的:(AlertDialog)