1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| //文本框 <TextView android:id="@+id/TextViewId" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:textSize="24sp" android:textColor="#000000" android:text="TextView Content"/>
//按钮 <Button android:id="@+id/ButtonId" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button Content" android:textAllCaps="false"/> //按钮点击事件 Button button=(Button)findViewById(R.id.ButtonId); button.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ //点击逻辑 } });
//输入框 <EditText android:id="@+id/EditTextId" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Type Something Here" android:maxLines="2"/> //获取输入框内容 EditText editText=(EditText)findViewById(R.id.EditTextId); String inputText=editText.getText().toString();
//图片 <ImageView android:id="@+id/ImageViewId" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/imgName"/> //替换图片 ImageView imageView=(ImageView)findViewById(R.id.ImageViewId); imageView.setImageResource(R.drawable.imgName);
//进度条 <ProgressBar android:id="@+id/ProgressId" android:layout_width="match_parent" android:layout_height="wrap_content" style="?android:progressBarStyleHorizontal" android:max="100"/> //控制可见属性和进度 ProgressBar progressBar=(ProgressBar)findViewById(R.id.ProgressId); progressBar.getVisibility(); //得到当前状态 progressBar.setVisibility(View.VISIBLE); //View.INVISIBLE不可见 View.Gone移除空间 int progress=progressBar.getProgress(); //得到当前进度 progress+=10; progressBar.setProgress(progress); //设置进度
//弹出对话框 AlertDialog.Builder dialog=new AlertDialog.Builder(FirstActivity.this); dialog.setTitle("TitleName"); //标题 dialog.setMessage("Msg"); //内容 dialog.setCancelable(false); //可否取消 dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //确定按钮点击事件 } }); dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //取消按钮点击事件 } }); dialog.show();
//弹出进度条 ProgressDialog progressDialog=new ProgressDialog(FirstActivity.this); progressDialog.setTitle("TitleName"); progressDialog.setMessage("Msg"); progressDialog.setCancelable(true); progressDialog.show();
|