您的位置:首页 > 移动开发 > Android开发

#Android#常用控件使用方法

2016-04-22 09:02 399 查看

#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 OnClickListener
public 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相似
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: