中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

汕頭市手機(jī)網(wǎng)站建設(shè)品牌steam交易鏈接在哪里

汕頭市手機(jī)網(wǎng)站建設(shè)品牌,steam交易鏈接在哪里,福州交通建設(shè)集團(tuán)官方網(wǎng)站,大連短視頻代運(yùn)營一、概念 在 xml 中為控件設(shè)置的屬性。自定義屬性名稱如果使用系統(tǒng)已定義的&#xff0c;例如 textSize 會(huì)在編譯時(shí)報(bào)錯(cuò)。 格式類型定義/使用 string 字符串 <attr name "myContent" format "color" /> android:myContent "Hello Word!&quo…

一、概念?

在 xml 中為控件設(shè)置的屬性。自定義屬性名稱如果使用系統(tǒng)已定義的,例如 textSize 會(huì)在編譯時(shí)報(bào)錯(cuò)。

格式類型定義/使用

string 字符串

<attr name = "myContent" format = "color" />

android:myContent = "Hello Word!"

color 顏色

<attr name = "myTextColor" format = "color" />

android:myTextColor = "#00FF00"

dimension 尺寸

<attr name = "myTextSize" format = "dimension" />

android:myTextSize = "12.sp"

reference 資源

<attr name = "myBackground" format = "reference" />

android:myBackground = "@drawable/圖片ID"

boolean 布爾

<attr name = "myEnable" format = "boolean" />

android:myEnable = "true"

float 浮點(diǎn)

<attr name = "myAlpha" format = "float" />

android:myAlpha = "0.5F"

integer 整型

<attr name = "myMaxLines" format = "integer" />

android:myMaxLines = "3"

fraction 百分比

<attr name = "myOffset" format = "fraction" />

android:myOffset = "10%"

enum 枚舉

<attr name = "myOrientation">

? ? ? ? <enum name = "horizontal" value="0" />

????????<enum name = "vertical" value="1" />

</attr>

android:myOrientation = "vertical"

flag 位運(yùn)算

位運(yùn)算類型的屬性在使用的過程中可以使用多個(gè)值

<attr name = "myGravity" />

? ? ? ? <flag nema="top" value="0x01">

????????<flag nema="left" value="0x02">

????????<flag nema="center_vertical" value="0x02">

</attr>

android:myGravity = "top|left"

混合類型

屬性定義時(shí)可以指定多種類型值

<attr name = "myBackground" format = "reference|color" />

android:myBackground = "@drawable/圖片ID"

android:myBackground = "#00FF00"

二、自定義步驟

2.1 創(chuàng)建資源文件(屬性聲明)

右鍵 values 目錄 -> New File文件 -> 一般取名attrs.xml。

<resources><!--name使用自定義View的名稱--><declare-styleable name="MyView"><!--name屬性名稱,format格式--><attr name="myText" format="string" /><attr name="myTextColor" format="color" /><attr name="myTextSize" format="dimension" /><attr name="myMaxLength" format="integer" /><attr name="myBackground" format="reference|color" /><!--枚舉--><attr name="myInputType"><enum name="number" value="1"/><enum name="text" value="2"/></attr></declare-styleable>
</resources>

2.2?構(gòu)造函數(shù)中配置

constructor(context: Context?) : super(context)

重寫一個(gè)參數(shù)的構(gòu)造函數(shù),使用場景:代碼?new 創(chuàng)建實(shí)例的時(shí)候調(diào)用。

constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)

重寫兩個(gè)參數(shù)的構(gòu)造函數(shù),使用場景:xml中使用時(shí)調(diào)用(xml轉(zhuǎn)java代碼的時(shí)候反射)。

constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

重寫三個(gè)參數(shù)的構(gòu)造函數(shù),使用場景:使用主題Style的時(shí)候調(diào)用。

class MyView : View {private var text: String? = nullprivate var textSize: Int? = nullprivate var textColor: Int? = nullprivate var maxLength: Int? = nullprivate var background: Int? = nullprivate var inputType: Int? = null//改成this調(diào)用2個(gè)參數(shù)的構(gòu)造constructor(context: Context?) : this(context, null)//改成this調(diào)用3個(gè)參數(shù)的構(gòu)造constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)//在這里統(tǒng)一進(jìn)行處理constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {context?.let {//返回一個(gè)與attrs中列舉出的屬性相關(guān)的數(shù)組,數(shù)組里面的值由樣式屬性指定val attributes = it.obtainStyledAttributes(attrs, R.styleable.MyView)//獲取自定義屬性(格式:屬性名稱_條目名稱)text = attributes.getString(R.styleable.MyView_myText)textSize = attributes.getDimensionPixelSize(R.styleable.MyView_myTextSize, 0)textColor = attributes.getColor(R.styleable.MyView_myTextColor, Color.BLACK)maxLength = attributes.getInt(R.styleable.MyView_myMaxLength,1)background = attributes.getResourceId(R.styleable.MyView_myBackground,R.drawable.ic_launcher_foreground)inputType = attributes.getInt(R.styleable.MyView_myInputType,0)//回收資源attributes.recycle()}}
}

2.3?布局中使用(屬性使用)

  • 根布局添加命名空間(只需要輸入app,IDE會(huì)自動(dòng)補(bǔ)全)。
  • 控件名稱使用完整路徑(只需要輸入自定義View的類名,IDE會(huì)自動(dòng)補(bǔ)全)。
  • 未自定義的屬性View會(huì)去處理(繼承自View),使用自定義的屬性就是 app: 開頭的。
<!--根布局添加命名空間-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><!--控件名稱使用完整路徑--><com.example.kotlindemo.view.MyViewandroid:layout_width="match_parent"android:layout_height="wrap_content"app:myBackground="@drawable/ic_launcher_foreground"app:myInputType="number"app:myText="Hello Word!"app:myTextColor="@color/black"app:myTextSize="20sp"app:myMaxLength="20"/>
</LinearLayout>
http://www.risenshineclean.com/news/48017.html

相關(guān)文章:

  • 國外網(wǎng)站建設(shè)現(xiàn)狀圖分析產(chǎn)品經(jīng)理培訓(xùn)哪個(gè)機(jī)構(gòu)好
  • 網(wǎng)站開發(fā)哪個(gè)城市發(fā)展好東莞seo技術(shù)培訓(xùn)
  • android網(wǎng)站客戶端開發(fā)關(guān)鍵詞挖掘ppt
  • 網(wǎng)站怎么做關(guān)鍵詞搜索數(shù)據(jù)分析培訓(xùn)機(jī)構(gòu)哪家好
  • 濟(jì)南集團(tuán)網(wǎng)站建設(shè)公司好軟文范例100字以內(nèi)
  • 怎么查詢網(wǎng)站空間商百度一下你就知道了百度
  • 手機(jī)客戶端網(wǎng)站怎么做網(wǎng)絡(luò)營銷一般月薪多少
  • 如何做話費(fèi)卡回收網(wǎng)站株洲網(wǎng)頁設(shè)計(jì)
  • 織夢網(wǎng)站怎么上傳友鏈大全
  • 網(wǎng)站維護(hù)一年一般多少錢怎么建網(wǎng)站賣東西
  • 建設(shè)網(wǎng)站的行業(yè)現(xiàn)狀分析站長之家素材
  • 好的網(wǎng)站怎么設(shè)計(jì)師百度seo關(guān)鍵詞
  • 網(wǎng)站建設(shè)有幾種方式北京網(wǎng)站優(yōu)化外包
  • 廣西地礦建設(shè)集團(tuán)網(wǎng)站簡述什么是網(wǎng)絡(luò)營銷
  • 江陰市做網(wǎng)站的口碑營銷策劃方案
  • 珠海網(wǎng)站建設(shè)怎么樣如何制作自己的網(wǎng)站?
  • 一個(gè)空間做2個(gè)網(wǎng)站廣州現(xiàn)在有什么病毒感染
  • 長春火車站時(shí)刻表分享推廣
  • 邯鄲有學(xué)做搭建網(wǎng)站的嗎seo網(wǎng)站搜索優(yōu)化
  • 鑫菲互動(dòng)網(wǎng)站建設(shè)公司愛站seo查詢
  • 閥門網(wǎng)站建設(shè)國色天香站長工具
  • 網(wǎng)站底部圖片突發(fā)大事震驚全國
  • 做網(wǎng)站外快一年的百度指數(shù)
  • 昆明做網(wǎng)站競價(jià)品牌推廣策劃
  • 如何通過做威客賺錢長春網(wǎng)站優(yōu)化方案
  • 網(wǎng)站建設(shè)阿膠膏的作用優(yōu)化推廣網(wǎng)站淄博
  • 天津注冊公司網(wǎng)站宣傳網(wǎng)站怎么做
  • 做seo網(wǎng)站的公司媒體邀約
  • 建設(shè)好網(wǎng)站靠什么賺錢適合40歲女人的培訓(xùn)班
  • 貴陽網(wǎng)站建設(shè)黔搜seo顧問是什么職業(yè)