博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
android131 360 02 设置中心
阅读量:7224 次
发布时间:2019-06-29

本文共 5248 字,大约阅读时间需要 17 分钟。

// 判断是否需要自动更新        boolean autoUpdate = mPref.getBoolean("auto_update", true);        if (autoUpdate) {            checkVerson();        } else {            mHandler.sendEmptyMessageDelayed(CODE_ENTER_HOME, 2000);// 延时2秒后发送消息        }        // 渐变的动画效果        AlphaAnimation anim = new AlphaAnimation(0.3f, 1f);//透明度从0.3到1        anim.setDuration(2000);//延迟时间是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

自定义控件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 /*
触摸状态能不能获取焦点
*/ 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); } }}

 

本文转自农夫山泉别墅博客园博客,原文链接:http://www.cnblogs.com/yaowen/p/5095281.html,如需转载请自行联系原作者
你可能感兴趣的文章
https客户端证书导入
查看>>
用 PreparedStatement 向 SqlServer 中一次性插入多条记录
查看>>
Slackware-2014-0903
查看>>
CentOS下安装JDK1.7
查看>>
LDAP DIT设计参考
查看>>
iptables详解
查看>>
Protostuff 介绍
查看>>
一张图看懂开源许可协议,开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别...
查看>>
参数验证其实可以更简明一点
查看>>
Set up Mule runtime env with mule-standalone-3.6.0
查看>>
Linux基础-linux命令:csplit
查看>>
core_framework —— 基于libev的轻量级lua网络开发框架
查看>>
回到顶部
查看>>
DES/3DES(TripleDES)加密、解密测试数据
查看>>
Maven项目标准目录结构
查看>>
Tomcat 系统架构与设计模式,第 1 部分: 工作原理
查看>>
Hadoop输出参数信息详解(16)
查看>>
ERROR 2002 (HY000): Can't connect to local MySQL错误
查看>>
Java版冒泡排序法
查看>>
关于FB4.6插件安装后默认语言环境的更改问题
查看>>