我们有一个项目,可以在不同的屏幕尺寸上运行AlertDialog v7 AppComp的风格。我的问题是如何设置AlertDialog消息文本大小的样式?第二个问题,如何更改各种屏幕尺寸的AlertDialog大小?我用一个自己的xml文件写了一个CustomDialog作为一个Activity,这似乎工作正常,除了模拟器在运行时显示一个像xml文件视图的鬼魂!我最近看到过一篇文章暗示邮件的文本大小不能改变。我有一些关于如何使用DisplayMetrics的知识,但不想使用这个约定。为以下AletDialog和样式设计代码。如果有人能保证我的鬼影将不是一个真正的设备上显示出来,我可能干脆放弃,并用这个方法似乎笨重AlertDialog样式
private void doWhat() {
// R.style.MyAlertDialogStyle see res/values/styles
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this, R.style.MyAlertDialogStyle);
// Setting Dialog Title
alertDialog.setTitle("Confirm Reset of Password");
// Setting Dialog Message
alertDialog.setMessage("Click YES to create a new master password");
// Setting Icon to Dialog
alertDialog.setIcon(R.drawable.caution);
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to invoke YES event
db = helper.getReadableDatabase();
String q = "SELECT * FROM masterPW";
Cursor cursor = db.rawQuery(q,null);
// Above query gets TABLE_PW data from Col_IDI
// TABLE_PW will only ever have one row of data
int rowID = 99;
if(cursor.moveToFirst()){
rowID = cursor.getInt(cursor.getColumnIndex(Col_IDI));
str = cursor.getString(cursor.getColumnIndex(Col_MPW));
}
cursor.close();
// Line of code below WORKS deletes entire TABLE <=====
// Not a recomended way to re-set the master password
// db.delete(TABLE_PW, null, null);
String num = Integer.toString(rowID);
db.delete(TABLE_PW, Col_IDI + " = ?", new String[] { num });
db.close();
Intent intentYY = new Intent(DetailsActivity.this, MainActivity.class);
startActivity(intentYY);
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to invoke NO event
Toast.makeText(getApplicationContext(), "Password NOT Changed", Toast.LENGTH_SHORT).show();
dialog.cancel();
}
});
// Showing Alert Message and set the SIZE of the alertDialog
alertDialog.show().getWindow().setLayout(1300, 500);// was 1100 500
}
<!--Code below styles the AlertDialog.Builder on DetailsActivity -->
<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Dialog.Alert">
<!-- Used for the buttons -->
<item name="colorAccent">@color/color_deepBlue</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">@color/color_Black</item>
<item name="android:textSize">25sp</item>
<!-- Used for the background -->
<item name="android:background">@color/color_lightGray</item>
</style>
为您的警告对话框创建自定义布局,这会给你所有访问的TextView的造型,点击次数和等,然后设置对话框中查看到那个布局.. –
@AalapPatel所以只需创建一个自定义xml文件,而无需使用ActivityCustom并在使用CustomDialog的Activity的内部充入自定义xml –
什么是没有ActivityCustom? –