原生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);
相关文章
相关标签/搜索