我們有一個項目,可以在不同的屏幕尺寸上運行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? –