最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

淺析Android手機(jī)衛(wèi)士自定義控件的屬性

 更新時(shí)間:2016年04月08日 14:57:11   作者:陶士涵  
這篇文章主要介紹了淺析Android手機(jī)衛(wèi)士自定義控件的屬性,本文介紹的非常詳細(xì)具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧

推薦閱讀:淺析Android手機(jī)衛(wèi)士關(guān)閉自動(dòng)更新

上一節(jié)完成的自定義組合控件,靈活性不夠,控件的顯示信息上,仿照系統(tǒng)屬性,自定義自己的屬性

上一節(jié)組合控件SettingItemView中有三個(gè)控件,分別是TextView大標(biāo)題,TextView描述,CheckBox復(fù)選框

自定義屬性 tsh:title=”大標(biāo)題” 和tsh:desc_on=”小標(biāo)題開啟”,tsh:desc_off=”小標(biāo)題關(guān)閉”

添加命名空間,xmlns:tsh=”http://schemas.android.com/apk/res/包名"

在res/values/目錄下創(chuàng)建 attrs.xml文件

添加節(jié)點(diǎn) <declare-styleable name=”TextView”>

節(jié)點(diǎn)下添加節(jié)點(diǎn)<attr name=”title” format=”string”/>,添加其他兩個(gè)屬性的節(jié)點(diǎn)

在布局文件使用的時(shí)候,會(huì)調(diào)用帶有兩個(gè)參數(shù)的構(gòu)造方法

在這個(gè)構(gòu)造方法里面,會(huì)傳遞一個(gè)AttributeSet對象

調(diào)用AttributeSet對象的getAttributeValue()方法,得到屬性值,參數(shù):索引位置,不推薦

調(diào)用AttributeSet對象的getAttributeValue(namespace,name)方法,參數(shù):命名空間,屬性名

調(diào)用TextView對象的setText()方法,直接給設(shè)置進(jìn)去

描述部分,在setChecked()方法里面,判斷,再設(shè)置

SettingItemView.java

package com.qingguow.mobilesafe.ui;
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.qingguow.mobilesafe.R;
public class SettingItemView extends RelativeLayout {
private TextView tv_title;
private TextView tv_desc;
private CheckBox cb_status;
private String desc_on;
private String desc_off;
/**
* 初始化View對象
* @param context
*/
private void initView(Context context) {
View.inflate(context, R.layout.setting_item_view, this);
cb_status=(CheckBox) this.findViewById(R.id.cb_status);
tv_desc=(TextView) this.findViewById(R.id.tv_desc);
tv_title=(TextView) this.findViewById(R.id.tv_title);
}
/**
* 判斷是否選中
* @return
*/
public boolean isChecked(){
return cb_status.isChecked();
}
/**
* 設(shè)置是否選中
* @param status
*/
public void setChecked(boolean status){
if(status){
tv_desc.setText(desc_on);
}else{
tv_desc.setText(desc_off);
}
cb_status.setChecked(status);
}
/**
* 設(shè)置顯示文本
* @param text
*/
public void setDesc(String text){
tv_desc.setText(text);
}
public SettingItemView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initView(context);
}
public SettingItemView(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);     //獲取傳遞的屬性
String title=attrs.getAttributeValue("http://schemas.android.com/apk/res/com.qingguow.mobilesafe", "title");
tv_title.setText(title);
desc_on=attrs.getAttributeValue("http://schemas.android.com/apk/res/com.qingguow.mobilesafe", "desc_on");
desc_off=attrs.getAttributeValue("http://schemas.android.com/apk/res/com.qingguow.mobilesafe", "desc_off");
}
public SettingItemView(Context context) {
super(context);
initView(context);
}
}

activity_setting.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tsh="http://schemas.android.com/apk/res/com.qingguow.mobilesafe"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="#ccc"
android:gravity="center"
android:text="設(shè)置中心"
android:textSize="20sp" />
<com.qingguow.mobilesafe.ui.SettingItemView
tsh:title="設(shè)置自動(dòng)更新"
tsh:desc_on="設(shè)置自動(dòng)更新開啟"
tsh:desc_off="設(shè)置自動(dòng)更新關(guān)閉"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/siv_item">
</com.qingguow.mobilesafe.ui.SettingItemView>
</LinearLayout> 

attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="TextView">
<attr name="title" format="string" />
<attr name="desc_on" format="string" />
<attr name="desc_off" format="string" />
</declare-styleable>
</resources>

以上是針對Android手機(jī)衛(wèi)士自定義控件的屬性相關(guān)介紹,希望對大家有所幫助!

相關(guān)文章

  • Android懸浮窗的實(shí)現(xiàn)步驟

    Android懸浮窗的實(shí)現(xiàn)步驟

    最近想做一個(gè)懸浮窗秒表的功能,所以看下懸浮窗具體的實(shí)現(xiàn)步驟,接下來通過本文給大家介紹Android懸浮窗的實(shí)現(xiàn),需要的朋友可以參考下
    2024-01-01
  • Android使用Intent.ACTION_SEND分享圖片和文字內(nèi)容的示例代碼

    Android使用Intent.ACTION_SEND分享圖片和文字內(nèi)容的示例代碼

    這篇文章主要介紹了Android使用Intent.ACTION_SEND分享圖片和文字內(nèi)容的示例代碼的實(shí)例代碼,具有很好的參考價(jià)值,希望對大家有所幫助,一起跟隨小編過來看看吧
    2018-05-05
  • Android 監(jiān)聽手機(jī)GPS打開狀態(tài)實(shí)現(xiàn)代碼

    Android 監(jiān)聽手機(jī)GPS打開狀態(tài)實(shí)現(xiàn)代碼

    這篇文章主要介紹了Android 監(jiān)聽手機(jī)GPS打開狀態(tài)實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • Android使用第三方服務(wù)器Bmob實(shí)現(xiàn)發(fā)送短信驗(yàn)證碼

    Android使用第三方服務(wù)器Bmob實(shí)現(xiàn)發(fā)送短信驗(yàn)證碼

    這篇文章主要介紹了Android使用第三方服務(wù)器Bmob實(shí)現(xiàn)發(fā)送短信驗(yàn)證碼的思路詳解,需要的朋友可以參考下
    2016-09-09
  • Android實(shí)現(xiàn)Android?APP自動(dòng)更新功能

    Android實(shí)現(xiàn)Android?APP自動(dòng)更新功能

    在移動(dòng)應(yīng)用的全生命周期中,版本迭代和用戶更新體驗(yàn)至關(guān)重要,傳統(tǒng)的做法是依賴?Google?Play?商店強(qiáng)制推送更新,但在某些場景下,我們需要更即時(shí)地控制更新流程,所以本文給大家介紹了Android實(shí)現(xiàn)Android?APP自動(dòng)更新功能,需要的朋友可以參考下
    2025-04-04
  • Gradle的緩存路徑修改的四種方法(小結(jié))

    Gradle的緩存路徑修改的四種方法(小結(jié))

    這篇文章主要介紹了Gradle的緩存路徑修改的四種方法(小結(jié)),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07
  • ijkplayer打包支持https的so使用詳解

    ijkplayer打包支持https的so使用詳解

    這篇文章主要為大家介紹了ijkplayer打包支持https的so使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-11-11
  • Android?App頁面滑動(dòng)標(biāo)題欄顏色漸變詳解

    Android?App頁面滑動(dòng)標(biāo)題欄顏色漸變詳解

    這篇文章主要為大家詳細(xì)介紹了Android?App頁面滑動(dòng)標(biāo)題欄顏色漸變,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • Android 百分比布局詳解及實(shí)例代碼

    Android 百分比布局詳解及實(shí)例代碼

    這篇文章主要介紹了Android 百分比布局詳解及實(shí)例代碼的相關(guān)資料,這里附有代碼實(shí)例幫助大家學(xué)習(xí)參考,如何實(shí)現(xiàn)百分比布局,需要的朋友可以參考下
    2016-11-11
  • Android ImageView 固定寬高比例的實(shí)現(xiàn)方法

    Android ImageView 固定寬高比例的實(shí)現(xiàn)方法

    這篇文章主要介紹了Android ImageView 固定寬高比例的實(shí)現(xiàn)方法的相關(guān)資料,,方法一:設(shè)置 adjustViewBounds="true",方法二:使用 Universal-Image-Loader 圖片緩存類,需要注意的是方法二和方法一同時(shí)使用導(dǎo)致設(shè)置無效,需要的朋友可以參考下
    2017-07-07

最新評論

江门市| 衡南县| 涿州市| 潜山县| 文登市| 榆树市| 连山| 离岛区| 三亚市| 青岛市| 山西省| 湖北省| 泽州县| 梧州市| 高碑店市| 大关县| 洪泽县| 罗定市| 年辖:市辖区| 固阳县| 长岛县| 炎陵县| 赤城县| 禄劝| 武汉市| 莱州市| 蓝山县| 九江市| 三门峡市| 论坛| 革吉县| 旬阳县| 武宣县| 页游| 三门峡市| 包头市| 航空| 汕头市| 泸溪县| 明水县| 金山区|