#Android#常用控件使用方法

来源:互联网 发布:安卓系统软件 知乎 编辑:程序博客网 时间:2024/05/23 11:55

#Android#常用控件使用方法

  • TextView
    显示文字内容

  • EditText
    输入和编辑文字
    hint属性用于输入提示性文本
    android:inputType=”textPassword”为设置输入格式为密码格, android:inputType=”phone”为设置输入格式为拨号键盘

  • ImageView
    ImageView
    src用于加载图片,宽度为match_partent时不会被拉长,会自适应
    background用于设置背景,宽度为match_parent时会被拉长为父布局的宽度
    两者可以共存

  • Button&ImageButton
    button 有text属性
    imagebutton 有src属性
    都可以作为按钮产生点击事件和效果

  • ProcessBar
    显示进度条
    /*android的可见属性
    visibility 可见
    invisible 不可见
    gone 不仅不可见还不占用任何屏幕空间
    */
    用style可改成水平进度条

  • AlertDialog
    警告对话框,能够屏蔽替他控件的交互能力
    下面举个栗子

public class MainActivity extends Activity implements OnClickListenerpublic void onClick(View v){    swith(v.getId()){    case R.id.Button:      AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);      dialog.setTitle("This is a dialog");      dialog.setMessage("Something important");      dialog.setCancelable(false);//对话框不可用Back键取消      dialog.setPositiveButton("OK",new DialogInterface.OnClickListener(){      public void onClick(DialogInterface dialog,int which){      }      });      dialog.setNegativeButton("Cancel",new DialogInterface.OnClickListener(){      public void onClick(DialogInterface dialog,int which){      }      });      dialog.show();      break;    default:      break;      }    }  }}
  • ProcessDialog
    弹出进度条对话框,能屏蔽其他控件的交互能力
    用法与AlertDialog相似
0 0