android logo的loading,Android简单的loading

这个博客主要展示了如何在Android应用中创建和管理基础的Activity和Fragment。内容包括展示加载对话框的方法,监听键盘事件以防止意外退出,以及处理网络连接错误的提示。此外,还提供了关闭加载对话框的函数。
摘要由CSDN通过智能技术生成

1.BaseActivity

package com.xcf.admin.couldclass.Activitys.Base;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.graphics.drawable.ColorDrawable;

import android.support.v7.app.AppCompatActivity;

import android.view.KeyEvent;

import android.widget.Toast;

import com.xcf.admin.couldclass.R;

/**

* Created by mayiyahei on 2019/1/9.

*/

public class BaseAcitivity extends AppCompatActivity{

private AlertDialog alertDialog;

public void showLoadingDialog() {

alertDialog = new AlertDialog.Builder(this).create();

alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable());

alertDialog.setCancelable(false);

alertDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

@Override

public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_BACK)

return true;

return false;

}

});

alertDialog.show();

alertDialog.setContentView(R.layout.loading_alert);

alertDialog.setCanceledOnTouchOutside(false);

}

public void dismissLoadingDialog() {

if (null != alertDialog && alertDialog.isShowing()) {

alertDialog.dismiss();

}

}

public void linkerror(){

Toast.makeText(BaseAcitivity.this,"网络连接失败,请稍候重试",Toast.LENGTH_SHORT).show();

}

}

2.BaseFragment

package com.xcf.admin.couldclass.Activitys.Base;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.graphics.drawable.ColorDrawable;

import android.os.Bundle;

import android.support.annotation.Nullable;

import android.support.v4.app.Fragment;

import android.view.KeyEvent;

import android.widget.Toast;

import com.xcf.admin.couldclass.R;

import java.util.List;

/**

* Created by mayiyahei on 2019/1/9.

*/

public class BaseFragment extends Fragment{

private AlertDialog alertDialog;

public void showLoadingDialog() {

alertDialog = new AlertDialog.Builder(getActivity()).create();

alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable());

alertDialog.setCancelable(false);

alertDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {

@Override

public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_BACK)

return true;

return false;

}

});

alertDialog.show();

alertDialog.setContentView(R.layout.loading_alert);

alertDialog.setCanceledOnTouchOutside(false);

}

public void dismissLoadingDialog() {

if (null != alertDialog && alertDialog.isShowing()) {

alertDialog.dismiss();

}

}

public void linkerror(){

Toast.makeText(getContext(),"网络连接失败,请稍候重试",Toast.LENGTH_SHORT).show();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值