Android之登录页的等待页面,AVI(手把手教你写)
话不多说,先看效果(不会上传视频,就看照片吧)
3,使用,在MainActivity中(我这里用的是StarActivity,你们自己换成自己的Activity)
解释都在代码中(结构如下)
public class StarActivity extends AppCompatActivity {
private LinearLayout mPage1;
private LinearLayout mPage2;
//hander机制
Handler mHandler = new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
switch (msg.what){
//登录成功刷新界面
case 1:
//登录界面变回原样
mPage1.setAlpha((float) 1);
//登录等待界面不可见
mPage2.setVisibility(View.INVISIBLE);
Toast.makeText(StarActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_star);
init();
}
//
private void init() {
//登录界面
mPage1 = findViewById(R.id.page1);
//登录等待界面
mPage2 = findViewById(R.id.page2);
//设置mPage2不可见
mPage2.setVisibility(View.GONE);
//点击登录
findViewById(R.id.bt_s_1).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(StarActivity.this, "登录中...", Toast.LENGTH_SHORT).show();
//设置登录界面变灰
mPage1.setAlpha((float) 0.3);
//设置登录等待界面尅可见
mPage2.setVisibility(View.VISIBLE);
//进行你的操作
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//模拟登录成功
Message message = new Message();
message.what = 1;
message.obj = 1;
mHandler.sendMessage(message);
}
}).start();
}
});
}
}
4,运行试一下吧
作者:随风~吃鸡!