UI笔记

1.基础操作


    

2. 为按钮添加事件处理

public class MainActivity extends Activity implements OnClickListener {
  @Override
  public void onClick(View v) {
    switch(v.getId()) {
      case R.id.button:
      
        break;
      default:
        break;
    }
  }
}

3. 输入框


.java
private EditText editText;
editText = (EditText) findViewById(R.id.editText);

String inputText = editText.getText().toString();

4. ImageView



.java
imageView,setImageResource(R.drawable.jelly_bean)

5.进度条


通过设置控件的android:visibility属性来控制控件的可见性。
可选值:
- visible
- invisible
- gone
可以通过方法:
setVisibility()设置可见性,可以传入View.VISIBLE,View.INVISIBLE,View.GONE
通过方法: getVisibility()方法获取状态

可以设置成水平进度条
style="?android:attr/progressBarStyleHorizontal"
android:max = "100" #设置最大值

获取进度值
int progress = progressBar.getProgress();
progress = progress + 10;
progressBar.setProgress(progress);

6. AlertDialog

AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("This is Dialog");
dialog.setMessage("something import.");
dialog.setCancelable(false);
dialog.setPositiveButton("OK", new DialogInterface.OnClickLinstener(){
  @Override
  publlic void onClick(DialogInterface dialog, int which) {
    
  }
});

dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListenser() {
  @Override void onClick(DialogInterface dialog, int which) {

  }
});

dialog.show();

7. ProgressDialog

ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);

progressDialog.setTitle("This is a Progressdialog");
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(true);
progressDialog.show();

#如果设置setCancelable(false),要通过dismiss方法来关闭对话框

你可能感兴趣的:(UI笔记)