问题:
您可以清楚地看到按钮周围的填充
代码:
public void startGameDialog(){
Context context = GameBoardActivity.this;
ContextThemeWrapper ctw = new ContextThemeWrapper(context, R.style.AppBaseTheme);
AlertDialog.Builder startGameDialog = new AlertDialog.Builder(ctw);
startGameDialog.setTitle(getResources().getString(R.string.whats_your_name));
LinearLayout dialogLayout = new LinearLayout(context);
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
dialogLayout.setOrientation(LinearLayout.VERTICAL);
final EditText newName = new EditText(context);
newName.setLayoutParams(params);
newName.setText("");
final Button submit = new Button(context);
submit.setText(getString(R.string.done));
submit.setLayoutParams(params);
dialogLayout.addView(newName);
dialogLayout.addView(submit);
startGameDialog.setView(dialogLayout);
final Dialog dialog = startGameDialog.create();
OnClickListener onClick = new OnClickListener() {
@Override
public void onClick(View v) {
GameBoardActivity.NAME = newName.getText().toString();
dialog.dismiss();
setUpPlayers();
}
};
submit.setOnClickListener(onClick);
dialog.show();
dialog.setCancelable(false);
}
尝试的解决方案(均失败):
使用builder.create()
方法构建AlertDialog
并设置.setView(dialogLayout, 0, 0, 0, 0)
。
先尝试ViewGroup parent = (ViewGroup) dialogLayout.getParent()
再尝试删除父级的填充parent.setPadding(0, 0, 0, 0);
(这会返回NullPointerException
错误,因为您无法为Dialog
nor设置填充AlertDialog
。
还有其他想法吗?
提前致谢!
坏人杰拉德
Android中的默认按钮具有自然填充。您可以通过更改背景或布局XML上的样式将其删除。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句