zoukankan      html  css  js  c++  java
  • 弹框(AlertDialog)和提示信息Toast字体大小颜色设置

    一、AlertDialog:

                 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("温馨提示");
    builder.setMessage("是否进行下一个病人?");
    builder.setPositiveButton("是", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
    //处理你的操作

    }
    });
    builder.setNegativeButton("否", null);
    AlertDialog dialog = builder.create();
    dialog.show();
    //弹框设置字体颜色
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.BLUE);
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.BLUE);
    try {
    //获取mAlert对象
    Field mAlert = AlertDialog.class.getDeclaredField("mAlert");
    mAlert.setAccessible(true);
    Object mAlertController = mAlert.get(dialog);
    //获取mMessageView并设置大小颜色
    Field mMessage = mAlertController.getClass().getDeclaredField("mMessageView");
    mMessage.setAccessible(true);
    TextView mMessageView = (TextView) mMessage.get(mAlertController);
    mMessageView.setTextColor(Color.BLUE);
    // mMessageView.setTextSize(30);
    //获取mTitleView并设置大小颜色
    Field mTitle = mAlertController.getClass().getDeclaredField("mTitleView");
    mTitle.setAccessible(true);
    TextView mTitleView = (TextView) mTitle.get(mAlertController);
    mTitleView.setTextColor(Color.BLUE);
    // mTitleView.setTextSize(30);
    } catch (NoSuchFieldException e) {
    e.printStackTrace();
    } catch (IllegalAccessException e) {
    e.printStackTrace();
    }

    二、Toast:

    private Toast mToast;
    private void showTip(final String str){
    runOnUiThread(new Runnable() {
    @Override
    public void run() {
    if (mToast == null) {
    mToast = Toast.makeText(getApplicationContext(), "",
    Toast.LENGTH_SHORT);
    LinearLayout layout = (LinearLayout) mToast.getView();
    TextView tv = (TextView) layout.getChildAt(0);
    tv.setTextSize(18);
              tv.setTextColor(R.color.white);

    }
    //mToast.cancel();
    mToast.setGravity(Gravity.CENTER, 0, 0);
    mToast.setText(str);
    mToast.show();
    }
    });
    }

     

      例如:Toast提示"登录成功",直接使用showTip("登录成功")即可。
    注意:fragment里面使用时将runOnUiThread替换成getActivity().runOnUiThread即可。
    
    
    
    

     

  • 相关阅读:
    查找符号链接的目标
    升级到VS2013.Update.4的问题
    (转载)FT232RL通信中断问题解决办法总结
    WinForms中的Label的AutoSize属性
    VS2010中的查找和替换中正则的使用
    为什么SqlTransaction.Rollback会抛出SqlException(11,-2)(即SQL超时异常)
    腾讯内推 社会招聘 自助操作内推
    腾讯内推流程 社会招聘 腾讯面试流程
    golang sort包的使用(一)
    golang 结构体中空数组被序列化成null解决方法
  • 原文地址:https://www.cnblogs.com/dmrbell/p/11647945.html
Copyright © 2011-2022 走看看