And*_*eaF 3 android android-alertdialog
对于屏幕较小的特定设备,默认情况下警报消息太大,我想将其设置为自定义dp
我的警报是这样的
OnClickListener addNewItemListener = new OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(
MyActivity.this);
LinearLayout myLayout= new LinearLayout(MyActivity.this);
myLayout.setOrientation(LinearLayout.VERTICAL);
alert.setTitle(R.string.add_title);
alert.setMessage(R.string.add_message);
final TextView t1 = new TextView(MyActivity.this);
t1.setText("Name");
final EditText input1 = new EditText(MyActivity.this);
myLayout.addView(t1);
myLayout.addView(input1);
alert.setView(myLayout);
alert.setPositiveButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
});
alert.setNegativeButton(R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
try {
....
} catch (RuntimeException e) {
Alerts.DatiErrati(MyActivity.this);
}
}
});
alert.show();
}
};
Run Code Online (Sandbox Code Playgroud)
如何设置警报消息的文本大小?
编辑2:
这是您可以使用的最佳方法
AlertDialog.Builder builder = new Builder(this);
builder.setMessage("Record and Images will be deleted?")
.setTitle("MyTitle")
.setCancelable(true)
.setPositiveButton("Yes",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,
int id)
{
dialog.cancel();
finish();
}
})
.setNegativeButton("No",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,
int id)
{
dialog.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
TextView textView = (TextView) dialog.findViewById(android.R.id.message);
textView.setTextSize(40);
Run Code Online (Sandbox Code Playgroud)
您可以使用以下内容获取更大的文字
alert.setMessage(Html.fromHtml("<Big>"+getString(R.string.add_message)+"</Big>"));
Run Code Online (Sandbox Code Playgroud)
注意:您可以使用更大型的更多更大的文本
归档时间: |
|
查看次数: |
7194 次 |
最近记录: |