Android操作系统中默认的loading动画怎么调用
答案:2 悬赏:80 手机版
解决时间 2021-01-27 04:24
- 提问者网友:藍了天白赴美
- 2021-01-26 13:24
Android操作系统中默认的loading动画怎么调用
最佳答案
- 五星知识达人网友:笑迎怀羞
- 2021-01-26 14:52
progressdialog先添加要加载xml面
始隐藏其组件
显示progressdialog
延迟段间再显示其组件隐藏progressdialog
// 图片数量
private int count =8;
//图片ID数组
private int[] ids={R.drawable.r1,R.drawable.r2,R.drawable.r3,R.drawable.r4,
R.drawable.r5,R.drawable.r6,R.drawable.r7,R.drawable.r8};
private Handler handler;
private ImageView img_loading;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.loading);
img_loading = (ImageView) this.findViewById(R.id.img_loading);
handler = new Handler(){
public void handleMessage(Message msg)
{
img_loading.setImageDrawable(getDrawable(msg.what));
}
};
play();
}
private Drawable getDrawable(int id)
{
return this.getResources().getDrawable(ids[id]);
}
private void play()
{
new Thread(){
@SuppressWarnings("static-access")
@Override
public void run()
{
while(true)
{
for (int i = 0; i < count; i++)
{
handler.sendEmptyMessage(i);
try
{
this.sleep(100);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
}.start();
}
始隐藏其组件
显示progressdialog
延迟段间再显示其组件隐藏progressdialog
// 图片数量
private int count =8;
//图片ID数组
private int[] ids={R.drawable.r1,R.drawable.r2,R.drawable.r3,R.drawable.r4,
R.drawable.r5,R.drawable.r6,R.drawable.r7,R.drawable.r8};
private Handler handler;
private ImageView img_loading;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.loading);
img_loading = (ImageView) this.findViewById(R.id.img_loading);
handler = new Handler(){
public void handleMessage(Message msg)
{
img_loading.setImageDrawable(getDrawable(msg.what));
}
};
play();
}
private Drawable getDrawable(int id)
{
return this.getResources().getDrawable(ids[id]);
}
private void play()
{
new Thread(){
@SuppressWarnings("static-access")
@Override
public void run()
{
while(true)
{
for (int i = 0; i < count; i++)
{
handler.sendEmptyMessage(i);
try
{
this.sleep(100);
} catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
}.start();
}
全部回答
- 1楼网友:痴妹与他
- 2021-01-26 14:59
android中dialog的示例代码如下:
1.创建对象框
alertdialog.builder builder = new builder(context);
builder.settitle("请输入"); //设置对话框标题
builder.seticon(android.r.drawable.btn_star); //设置对话框标题前的图标
2.创建edittext输入框
final edittext edit = new edittext(context);
3.将输入框赋值给dialog,并增加确定取消按键
builder.setview(edit);
builder.setpositivebutton("确认", new dialoginterface.onclicklistener() {
@override
public void onclick(dialoginterface dialog, int which) {
toast.maketext(context, "你输入的是: " + edit.gettext().tostring(), toast.length_short).show();
}
});
builder.setnegativebutton("取消", new dialoginterface.onclicklistener() {
@override
public void onclick(dialoginterface dialog, int which) {
toast.maketext(context, "你点了取消", toast.length_short).show();
}
});
4.设置常用api,并show弹出
builder.setcancelable(true); //设置按钮是否可以按返回键取消,false则不可以取消
alertdialog dialog = builder.create(); //创建对话框
dialog.setcanceledontouchoutside(true); //设置弹出框失去焦点是否隐藏,即点击屏蔽其它地方是否隐藏
dialog.show();
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯