android 网络异常提示
来源:互联网 发布:arduino 单片机 编辑:程序博客网 时间:2024/05/08 23:52
- 整体设计思路
当一个app当中有多个activity在共同的位置提示无网络环境(或者其他的内容),且进行刷新进一步操作时,就可以在同一个主activity里面实现这部分操作,其他activity继承这个主activity。 - 具体实现
主activity网络环境提示basenet_fragment.xml片段,将共同的提示部分直接写在主activity的布局当中
<include android:id="@+id/no_connection_view" android:layout_width="match_parent" android:layout_height="34dp" android:layout_below="@id/main_title" layout="@layout/activity_base_nonet_layout" />
具体布局activity_base_nonet_layout.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/connect_error_bg" android:gravity="center_vertical" android:orientation="horizontal" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="6dp" android:layout_marginRight="6dp" android:background="@drawable/common_error_ic" /> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:lines="1" android:text="@string/connect_error_text" android:textColor="@color/noconnect_text_color" android:textSize="12dp" /> <TextView android:id="@+id/retry_tv" android:layout_width="wrap_content" android:layout_height="22dp" android:layout_marginRight="8dp" android:paddingLeft="2dp" android:paddingRight="2dp" android:minWidth="54dp" android:background="@drawable/retry_selector" android:clickable="true" android:gravity="center|center_vertical" android:text="@string/manageapp_downloadstate_retry" android:textColor="@color/white" android:textSize="12dp" /></LinearLayout>
类图解析:
ConnectChangeReceiver监听网络状态的变化,如果有网络状态变化,通过OnConnectChangedListener实现类也就是BaseNetAppFragmentActivity处理变化的后续动作。
其中,BaseNetAppFragmentActivity实现了OnConnectChangedListener这个接口,而ConnectChangeReceiver监听器通过回调OnConnectChangedListener的onConnectChange()方法,去通知BaseNetAppFragmentActivity进行相应的操作。
/**
* --------------
* 欢迎转载 | 转载请注明
* --------------
* 如果对你有帮助,请点击|顶|
* --------------
* 请保持谦逊 | 你会走的更远
* --------------
* @author css
* @github https://github.com/songsongbrother
* @blog http://blog.csdn.net/xiangxi101
*/
0 0
- android 网络异常提示
- android 网络连接异常
- android 一些网络异常
- Android AlertDialog 提示设置网络
- Android M提示网络变化
- android编译单独模块时异常提示
- android编译单独模块时异常提示
- android网络访问异常:android.os.NetworkOnMainThreadException
- 异常提示
- Android检测网络连接并提示
- Android studio更新提示网络问题
- Android 监听网络变化弹出提示窗口
- android 网络加载提示进度封装 View
- Android 访问网络时抛 UnknownHostException异常
- Android 网络下载报networkonmainthreadexception异常
- android 4.0 主线程访问网络异常
- Android中解决网络连接异常
- 关于android中对异常的友情提示做处理。
- mysql升级
- UI基础3 UIControl
- SQL Server系列(9) -- 数据库的安全与备份
- 网络IPC:套接字值寻址
- 驱动测试错误集锦
- android 网络异常提示
- -webkit-text-size-adjust: none;
- 【模板】【bzoj3224】Tyvj 1728 普通平衡树 Splay
- 275、H-Index II
- 模拟快递100请求 通过快递单号获取物流信息
- 多线程操作之线程概念
- mysql查询所有记录,并去掉重复的记录
- SDWebImage内部实现过程
- 英国MBA专业