内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

Android中怎么在xml中設(shè)置自定義屬性-創(chuàng)新互聯(lián)

Android中怎么在xml中設(shè)置自定義屬性,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來(lái)學(xué)習(xí)下,希望你能有所收獲。

站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到奇臺(tái)網(wǎng)站設(shè)計(jì)與奇臺(tái)網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站制作、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名申請(qǐng)、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋奇臺(tái)地區(qū)。

1. 在項(xiàng)目中的values文件中創(chuàng)建attrs文件

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
 
 <declare-styleable name="QLoadingIndicatorView"> 
   
  <attr name="indicatorId" format="integer"/> 
  <attr name="indicatorColor" format="color"/> 
  <attr name="indicatorText" format="string"/> 
 </declare-styleable> 
 
</resources>
<pre name="code" class="java"></pre> 
<h4><a name="t3"></a>2. 在view中關(guān)聯(lián)這些屬性</h4> 
<div><pre name="code" class="java">public class MyView extends LinearLayout { 
 
 private int mIndicatorColor,mIndicatorId; 
 private String mIndicatorText; 
 
 public MyView(Context context, AttributeSet attrs, int defStyleAttr) { 
  super(context, attrs, defStyleAttr); 
 
  //從xml的屬性中獲取到值,然后想怎么用就怎么用 
  TypedArray ta=context.obtainStyledAttributes(attrs,R.styleable.QLoadingIndicatorView); 
  mIndicatorColor=ta.getColor(R.styleable.QLoadingIndicatorView_indicatorColor,Color.BLACK);//第二個(gè)參數(shù)是設(shè)置的默認(rèn)值,當(dāng)你不設(shè)置這個(gè)屬性時(shí)會(huì)使用這個(gè)值 
  mIndicatorId=ta.getInt(R.styleable.QLoadingIndicatorView_indicatorId,1); 
  mIndicatorText=ta.getString(R.styleable.QLoadingIndicatorView_indicatorText,"abc"); 
  ta.recycle(); 
 
 } 
}</pre><br> 
<br> 
</div> 
<pre name="code" class="java"></pre><pre name="code" class="java"></pre> 
<h4><a name="t4"></a>3.xml文件中設(shè)置屬性和命名空間</h4> 
<div><pre name="code" class="java"><GridLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 xmlns:app="http://schemas.android.com/apk/res-auto" //這就是自己定義的屬性的命名空間,androidstudio是這樣寫的,添加屬性的時(shí)候自動(dòng)生成 
 android:rowCount="9" 
 android:columnCount="4"> 
 <com.zxq.com.myrecycleview.progressbaranimation.QLoadingIndicatorView 
  android:layout_width="50dp" 
  android:layout_height="50dp" 
  android:layout_margin="10dp" 
  app:indicatorId="0"  //自己的設(shè)置的屬性    
  app:indicatorColor="#F00" 
  > 
 </com.zxq.com.myrecycleview.progressbaranimation.QLoadingIndicatorView> 
</GridLayout></pre><br> 
<br> 
</div> 
<pre name="code" class="java"> 
<pre></pre> 
<pre></pre> 
<pre></pre> 
<pre></pre> 
</pre>

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。

網(wǎng)站題目:Android中怎么在xml中設(shè)置自定義屬性-創(chuàng)新互聯(lián)
本文來(lái)源:http://m.rwnh.cn/article10/ggjgo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站內(nèi)鏈、網(wǎng)站收錄、企業(yè)建站、網(wǎng)頁(yè)設(shè)計(jì)公司響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

綿陽(yáng)服務(wù)器托管
阿瓦提县| 镇江市| 遵义市| 东宁县| 安阳县| 会理县| 哈尔滨市| 白城市| 开远市| 滁州市| 龙州县| 永善县| 西盟| 承德县| 新疆| 墨玉县| 阿荣旗| 合川市| 灵寿县| 崇仁县| 亚东县| 朝阳县| 津南区| 义乌市| 万山特区| 乌鲁木齐县| 留坝县| 五大连池市| 定边县| 原平市| 武陟县| 喀喇沁旗| 宕昌县| 改则县| 盖州市| 东平县| 义马市| 苏州市| 沈阳市| 腾冲县| 鸡泽县|