• 设置字体大小的对话框


     1 /**
     2  * 
     3  * 事件监听
     4  */
     5     @Override
     6     public void onClick(View v) {
     7         switch (v.getId()) {
     8         case R.id.item_back:
     9             finish();
    10             overridePendingTransition(R.anim.lefttoright, R.anim.righttoleft);
    11             break;
    12         case R.id.item_textsize:
    13             showcchoosedig();
    14 
    15         default:
    16             break;
    17         }
    18         
    19     }
    20 
    21     /**
    22      * 
    23      * 显示对话框
    24      */
    25 
    26     private int mcurrentChooseitem;//记录当前选中的item
    27     private int mcurrentitem=2;//记录当前选择确定后更改的字体
    28     private String url;
    29     
    30     private void showcchoosedig() {
    31         AlertDialog.Builder builder = new AlertDialog.Builder(this);//建立对话框
    32         
    33         String[] items=new String[]{"超大号字体","大号字体","正常字体","小号字体","超小号字体"};
    34         
    35         builder.setTitle("字体设置");
    36         builder.setSingleChoiceItems(items, mcurrentitem, new DialogInterface
    37                 .OnClickListener() {
    38             
    39             @Override
    40             public void onClick(DialogInterface dialog, int which) {
    41                 System.out.println("选中:"+which);
    42                 mcurrentChooseitem=which;
    43                 
    44             }
    45         });
    46         
    47         /**
    48          * 设置确定按钮的监听
    49          */
    50 
    51         builder.setPositiveButton("确定", new OnClickListener() {
    52             
    53             @Override
    54             public void onClick(DialogInterface dialog, int which) {
    55                  WebSettings settings = item_webnews.getSettings();//创建websetting的对象
    56                  switch (mcurrentChooseitem) {
    57                 case 0:
    58                     settings.setTextSize(TextSize.LARGER);
    59                     break;
    60                 case 1:
    61                     settings.setTextSize(TextSize.LARGEST);
    62                     break;
    63                 case 2:
    64                     settings.setTextSize(TextSize.NORMAL);
    65                     break;
    66                 case 3:
    67                     settings.setTextSize(TextSize.SMALLER);
    68                     break;
    69                 case 4:
    70                     settings.setTextSize(TextSize.SMALLEST);
    71                     break;    
    72 
    73                 default:
    74                     break;
    75                 }
    76                  mcurrentitem=mcurrentChooseitem;//确定点击之后,字体变为所选择的字体大小
    77                 
    78             }
    79             
    80             
    81         });
    82         
    83         /**
    84          * 设置取消按钮
    85          */
    86         builder.setNegativeButton("取消", null);//不需要设置监听,因为默认点击就取消
    87         
    88         builder.show();//将对话框展现
    89 
    90     
    91    }
  • 相关阅读:
    Python学习4
    Python学习3
    Python学习2
    表空间
    sqlplus常用设置
    HashMap和LinkedHashMap
    堆栈源码
    观察者模式
    策略模式
    java线性表
  • 原文地址:https://www.cnblogs.com/wangying222/p/5586774.html
Copyright © 2020-2023  润新知