原生Dialog字體顏色等屬性

 

AlertDialog.Builder builder = new AlertDialog.Builder(VideoActivity.this);
builder.setTitle("舒適提示");
builder.setMessage("當前是運營商網絡,繼續觀看將消耗較多流量,產生高額流量費,是否繼續觀看");
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        finish();
    }
});
builder.setPositiveButton("肯定", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                //視頻播放
                jzVideoPlayerStandard.startVideo();
            }
        });
    }
});
AlertDialog dialog = builder.create();
if(hasWindowFocus()) {
    dialog.show();
    daiogbug(dialog);
}
try {
    Field mAlert = AlertDialog.class.getDeclaredField("mAlert");
    mAlert.setAccessible(true);
    Object mAlertController = mAlert.get(dialog);

    Field mMessage = mAlertController.getClass().getDeclaredField("mMessageView");
    mMessage.setAccessible(true);
    TextView mMessageView = (TextView) mMessage.get(mAlertController);
    mMessageView.setTextColor(Color.GRAY);//更改內容的顏色

} catch (IllegalAccessException e) {
    e.printStackTrace();
} catch (NoSuchFieldException e) {
    e.printStackTrace();
}

try {
    Field mAlert = AlertDialog.class.getDeclaredField("mAlert");
    mAlert.setAccessible(true);
    Object alertController = mAlert.get(dialog);

    Field mTitleView = alertController.getClass().getDeclaredField("mTitleView");
    mTitleView.setAccessible(true);

    TextView title = (TextView) mTitleView.get(alertController);
    title.setTextColor(Color.BLACK);//更改標題的顏色

} catch (NoSuchFieldException e) {
    e.printStackTrace();
} catch (IllegalArgumentException e) {
    e.printStackTrace();
} catch (IllegalAccessException e) {
    e.printStackTrace();
}

//更改按鈕顏色
dialog.getButton(dialog.BUTTON_NEGATIVE).setTextColor(Color.BLACK);
dialog.getButton(dialog.BUTTON_POSITIVE).setTextColor(Color.BLACK);
相關文章
相關標籤/搜索