底部导航栏文字、图片切换:
drawable —>new —>DrawableResourceFile
图片:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/xiaoxi"></item>
<item android:state_checked="false" android:drawable="@drawable/xiaoxi2"></item>
</selector>
文字:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#5EC746"></item>
<item android:state_checked="false" android:color="#5E5B5B"></item>
</selector>
8中Dialog
1.普通对话框
public void one(){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_launcher_background);
builder.setTitle("");
builder.setMessage("");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "确定", Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show();
}
});
dialog = builder.create();
dialog.show();
}
2.自定义对话框
public void dialog(){
View view = View.inflate(this,R.layout.layout,null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(view);
view.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog = builder.create();
dialog.show();
}
3.单选对话框
String str = "";
public void dialog(){
final String[] skill = {"神威","地爆天星","万象天引","尾兽玉"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_launcher_background);
builder.setTitle("请选择技能");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, str, Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show();
}
});
builder.setSingleChoiceItems(skill, 3, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
str = skill[which];
}
});
dialog = builder.create();
dialog.show();
}
4.多选对话框
public void dialog(){
final String[] skill = new String[]{"神威","地爆天星","万象天引","尾兽玉"};
final boolean[] flag = new boolean[]{true,false,false,true};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setIcon(R.drawable.ic_launcher_background);
builder.setTitle("请选择技能");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for (int i = 0; i < flag.length; i++){
if(flag[i]){
Toast.makeText(MainActivity.this, skill[i], Toast.LENGTH_SHORT).show();
}
}
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "取消", Toast.LENGTH_SHORT).show();
}
});
builder.setMultiChoiceItems(skill, flag, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
flag[which] = isChecked;
}
});
dialog = builder.create();
dialog.show();
}
5.水平进度条
public void dialog(){
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setMessage("正在加载......");
dialog.setMax(100);
dialog.show();
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
int prograss = 0;
@Override
public void run() {
if(prograss==100){
dialog.dismiss();
timer.cancel();
}
dialog.setProgress(prograss+=10);
}
},0,1000);
}
6.圆形进度条
public void dialog(){
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setMax(100);
dialog.setMessage("正在加载......");
dialog.show();
final Timer timer = new Timer();
timer.schedule(new TimerTask() {
int prograss = 0;
@Override
public void run() {
if(prograss==100){
dialog.dismiss();
timer.cancel();
}
dialog.setProgress(prograss+=10);
}
},0,1000);
}
7.日期对话框
public void dialog(){
Calendar calendar = Calendar.getInstance();
new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
Toast.makeText(MainActivity.this, year+"年"+month+"月"+dayOfMonth+"日", Toast.LENGTH_SHORT).show();
}
},calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH)).show();
}
8时间对话框
public void dialog(){
Calendar calendar = Calendar.getInstance();
new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Toast.makeText(MainActivity.this, hourOfDay+"时"+minute+"分", Toast.LENGTH_SHORT).show();
}
},calendar.get(Calendar.HOUR),calendar.get(Calendar.MINUTE),true).show();
}