android131 360 02 设置中心
// 判断是否需要自动更新
boolean autoUpdate = mPref.getBoolean("auto_update", true);
if (autoUpdate) {
checkVerson();
} else {
mHandler.sendEmptyMessageDelayed(CODE_ENTER_HOME, );// 延时2秒后发送消息
}
// 渐变的动画效果
AlphaAnimation anim = new AlphaAnimation(0.3f, 1f);//透明度从0.3到1
anim.setDuration();//延迟时间是2秒
rlRoot.startAnimation(anim);//rlRoot是闪屏页xml的根布局
SettingActivity.java
package com.itheima52.mobilesafe.activity; import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener; import com.itheima52.mobilesafe.R;
import com.itheima52.mobilesafe.view.SettingItemView; /**
* 设置中心
*/
public class SettingActivity extends Activity { private SettingItemView sivUpdate;// 设置升级
private SharedPreferences mPref; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting); mPref = getSharedPreferences("config", MODE_PRIVATE); sivUpdate = (SettingItemView) findViewById(R.id.siv_update);
// sivUpdate.setTitle("自动更新设置"); boolean autoUpdate = mPref.getBoolean("auto_update", true);//是否自动更新,true是默认值。 if (autoUpdate) {
// sivUpdate.setDesc("自动更新已开启");
sivUpdate.setChecked(true);
} else {
// sivUpdate.setDesc("自动更新已关闭");
sivUpdate.setChecked(false);
} sivUpdate.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// 判断当前的勾选状态
if (sivUpdate.isChecked()) {
// 设置不勾选
sivUpdate.setChecked(false);
// sivUpdate.setDesc("自动更新已关闭");
// 更新是否自动更新
mPref.edit().putBoolean("auto_update", false).commit();
} else {
sivUpdate.setChecked(true);
// sivUpdate.setDesc("自动更新已开启");
// 更新是否自动更新
mPref.edit().putBoolean("auto_update", true).commit();
}
}
});
}
}
activity_setting.xml
<!--
xmlns:android="http://schemas.android.com/apk/res/android"中的android是命名空间,
xmlns:itheima="http://schemas.android.com/apk/res/com.itheima52.mobilesafe"中的itheima是命名空间,com.itheima52.mobilesafe是清单文件中的包名。
-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:itheima="http://schemas.android.com/apk/res/com.itheima52.mobilesafe"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
style="@style/TitleStyle"
android:text="设置中心" />
<!--style.xml
<style name="TitleStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">50dp</item>
<item name="android:background">#8866ff00</item>
<item name="android:gravity">center</item>
<item name="android:textColor">@color/black</item>
<item name="android:textSize">22sp</item>
</style>
--> <!-- 加载这个控件的时候会去调用SettingItemView的构造函数,
调用构造函数的时候会去执行initView()方法加载R.layout.view_setting_item布局。 -->
<com.itheima52.mobilesafe.view.SettingItemView
android:id="@+id/siv_update"
android:layout_width="match_parent"
android:layout_height="wrap_content"
itheima:desc_off="自动更新已关闭"
itheima:desc_on="自动更新已开启"
itheima:title="自动更新设置" /> <!--自定义属性,values文件夹下attrs.xml,SettingItemView相当于是一个TextView,下面是TextView的属性。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SettingItemView">
<attr name="title" format="string" />
<attr name="desc_on" format="string" />
<attr name="desc_off" format="string" />
</declare-styleable>
</resources> --> </LinearLayout>
自定义控件SettingItemView.java
package com.itheima52.mobilesafe.view; import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView; import com.itheima52.mobilesafe.R; /**
* 设置中心的自定义组合控件
*/
public class SettingItemView extends RelativeLayout {//RelativeLayout是一个ViewGroup也就是一个View的容器。
//NAMESPACE是xmlns:itheima="http://schemas.android.com/apk/res/com.itheima52.mobilesafe"中itheima的位置。
private static final String NAMESPACE = "http://schemas.android.com/apk/res/com.itheima52.mobilesafe";
private TextView tvTitle;
private TextView tvDesc;
private CheckBox cbStatus;
private String mTitle;
private String mDescOn;
private String mDescOff;
//xml布局解析成java对象的时候有style走这个方法
public SettingItemView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initView();
}
//xml布局解析成java对象的时候有属性走这个方法
public SettingItemView(Context context, AttributeSet attrs) {
super(context, attrs);
mTitle = attrs.getAttributeValue(NAMESPACE, "title");// 根据属性名称,获取属性的值
mDescOn = attrs.getAttributeValue(NAMESPACE, "desc_on");
mDescOff = attrs.getAttributeValue(NAMESPACE, "desc_off");
initView(); int attributeCount = attrs.getAttributeCount();
for (int i = 0; i < attributeCount; i++) {
String attributeName = attrs.getAttributeName(i);
String attributeValue = attrs.getAttributeValue(i);
System.out.println(attributeName + "=" + attributeValue);
}
}
//不通过xml布局用代码new走这个方法
public SettingItemView(Context context) {
super(context);
initView();
} /**
* 初始化布局
*/
private void initView() {
// 将自定义好的布局文件设置给当前的SettingItemView,this将成为view_setting_item的父容器,this是一个ViewGroup是一个view容器可以拥有子布局。
View.inflate(getContext(), R.layout.view_setting_item, this);//View里面用getContext()拿到context对象。
//view_setting_item.xml
/*<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp" 整个RelativeLayout的高度
android:padding="5dp" >
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="22sp" />
<TextView
android:id="@+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/tv_title"
android:layout_marginTop="3dp"
android:textColor="#a000"
android:textSize="18sp" />
<CheckBox
android:id="@+id/cb_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:clickable="false" 不能点击
android:focusable="false" 不能获取焦点
android:focusableInTouchMode="false" /> 触摸状态能不能获取焦点
<View
android:layout_width="match_parent"
android:layout_height="0.2dp"
android:layout_alignParentBottom="true"
android:background="#a000" />
</RelativeLayout>*/
tvTitle = (TextView) findViewById(R.id.tv_title);
tvDesc = (TextView) findViewById(R.id.tv_desc);
cbStatus = (CheckBox) findViewById(R.id.cb_status); setTitle(mTitle);// 设置标题
} public void setTitle(String title) {
tvTitle.setText(title);
} public void setDesc(String desc) {
tvDesc.setText(desc);
} /**
* 返回勾选状态
*/
public boolean isChecked() {
return cbStatus.isChecked();
} public void setChecked(boolean check) {
cbStatus.setChecked(check); // 根据选择的状态,更新文本描述
if (check) {
setDesc(mDescOn);
} else {
setDesc(mDescOff);
}
}
}
android131 360 02 设置中心的更多相关文章
- android131 360 01 闪屏页和主页面
主界面: 软件升级流程: 清单文件: <?xml version="1.0" encoding="utf-8"?> <manifest xml ...
- android131 360 03 输入密码
package com.itheima52.mobilesafe.activity; import android.app.Activity; import android.app.AlertDial ...
- android131 360 05 手势触摸滑动,sim卡,开机启动的广播,手机联系人,SharedPreferences,拦截短信
安卓手势触摸滑动: package com.itheima52.mobilesafe.activity; import android.app.Activity; import android.con ...
- android131 360 04 手机安全页面
## Root权限 ## > 什么是Root权限? Root权限相当于系统管理员权限, 有了root权限,就可以随意修改和删除手机内部的文件. > 一般手机购买之后, 都没有root权限. ...
- AWR報告詳解
AWR是Oracle 10g 版本 推出的新特性, 全称叫Automatic Workload Repository-自动负载信息库, AWR 是通过对比两次快照(snapshot)收集到的统计信息 ...
- 02.Windows2012R2安装360安全卫士失败及无法卸载问题
问题: Windows 2012 R2 安装360安全卫士失败及无法卸载,导致网络无法通信问题解决. 解决:1.进入 Windows2012R2 安全模式下:2.进行覆盖安装360安全卫士:3.覆盖安 ...
- [原创]LoadRunner 12.02 录制脚本时提示无Internet访问,如何解决?
在使用LoadRunner 12.02 进行录制脚本时提示无Internet访问,如下图: 翻译中文如下: 可以尝试以下方式解决:点击弹出框中的“Yes”即可. 若还是有问题,尝试以下方式: (1)L ...
- 《30天自制操作系统》笔记(02)——导入C语言
<30天自制操作系统>笔记(02)——导入C语言 进度回顾 在上一篇,记录了计算机开机时加载IPL程序(initial program loader,一个nas汇编程序)的情况,包括IPL ...
- 分享4种CSS3效果(360度旋转、旋转放大、放大、移动)
转自:http://www.j q-school.com/Show.aspx?id=281 本文仅供自己学习而转载,由于效果掩饰地址的转载出现问题,强烈建议去源 ...
随机推荐
- C#控件背景透明的几种解决方案
已经很少做winform程序了,最新参与了一个小项目,遇到了控件背景透明的功能要求,特在此总结一下,供有需要的同行参考. 0.背景透明的概念和分类 背景透明是啥意思呢,就是背景透明.哈哈,废话了.其实 ...
- BZOJ2140: 稳定婚姻
题解: 题意就是求二分图的必须边. 我们有结论: 在残量网络上跑tarjan,对于一条边(u,v) 如果该边满流||scc[u]==scc[v],那么该边是可行边. 因为如果scc[u]==scc[v ...
- ShopNc商城修改详情
1. 修改400电话.(400.png) a.位置:在页面顶部搜索的后面. b.修改文件: t/layout/home_layout.php 增标签 <img border=0 src=&quo ...
- Java中的volatile
关于volatile 在JVM 1.2之前,Java的内存模型实现总是从主存读取变量,是不需要进行特别的注意的.而随着JVM的成熟和优化,现在在多线程环境下 volatile关键字的使用变得非常重要. ...
- php网页显示正方形图片缩略图
需求是这样的:原始图片的大小是不定的,类似800*600.1000*756,现有一个页面要以正方形(60*60)显示这些图片,注意:图片只能在内存处理,不能缩小后保存到本地磁盘. 解决办法: html ...
- Apache配置虚拟目录和多主机头
呃,相当古老的话题了,不过网上的资料实在是太坑爹,无奈只能自己动手做个备忘了...这里不提虚拟目录和主机头的区别了,不懂得童鞋去面壁思过吧 多个虚拟目录 首先把Apache安装到D:\Program ...
- 16、传感器(Sensor)
一.什么是传感器 传感器是一种物理装置或生物器官,能够探测.感受外界的信号.物理条件(如光.热.湿度)或化学组成(如烟雾),并将探知的信息传递给其他装置或器官.国家标准GB7665—87对传感器的定义 ...
- Robotium自动化测试报告生成
使用Robotium进行测试的时候,要想可以导出可视的测试结果,可以使用junitreport来实现junitreport下载地址:https://github.com/jsankey/android ...
- js基础第八天
返回前面起第一个字符位置 indexOf("sdfsdf");它是从左边索引为0开始数,而且只找第一个,然后返回该字符的位置.返回是个数值.如果找不到该字符,那么就会返回-1. 返 ...
- git和repo入门
版本控制 版本控制是什么已不用在说了,就是记录我们对文件.目录或工程等的修改历史,方便查看更改历史,备份以便恢复以前的版本,多人协作... 一.原始版本控制 最原始的版本控制是纯手工的版本控制:修改文 ...