概要
- 继承 android的Dialog类
- 在onCreate方法中设置自定义的dialog的内容
- .如果想要修改dialog的一些特性(比如:宽高、内容颜色等,要在show()调用后再修改)
例子
- 继承 android的Dialog类
public class ScoreDialog extends Dialog
implements View.OnClickListener {
- 在onCreate方法中设置自定义的dialog的内容
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View contentView = View.inflate(getContext(), R.layout.pc_view_edittextdialog, null);
setContentView(contentView);
mDialogView = getWindow().getDecorView().findViewById(android.R.id.content);
score_et = (EditText) findViewById(R.id.score_et);
//score_et.setFilters(new InputFilter[]{new InputFilter10()});
commit_tv = (TextView) contentView.findViewById(R.id.commit_tv);
commit_tv.setOnClickListener(this);
}
- 如果想要修改dialog的一些特性(比如:宽高、内容颜色等,要在show()调用后再修改)
public void show() {
super.show();
// 修改Dialog的宽高
Window window = getWindow();
WindowManager windowManager = window.getWindowManager();
Display display = windowManager.getDefaultDisplay();
WindowManager.LayoutParams lp = window.getAttributes();
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
ApplicationProxy singleInstance = ApplicationProxy.getSingleInstance();
Context applicationContext = singleInstance.getApplicationContext();
lp.width = (int) applicationContext.getResources().getDimension(R.dimen.pc_dimen_315dp);
window.setAttributes(lp);
}
public void btn(View view) {
ScoreDialog editTextDialog = new ScoreDialog(this);
editTextDialog.show();
editTextDialog.setHitText("hahahaha");
}