当前位置: 首页 > news >正文

宁波高端网站设计价格竞价推广渠道

宁波高端网站设计价格,竞价推广渠道,张店政府网站建设托管,温州外贸网站建设一、概念 在 xml 中为控件设置的属性。自定义属性名称如果使用系统已定义的&#xff0c;例如 textSize 会在编译时报错。 格式类型定义/使用 string 字符串 <attr name "myContent" format "color" /> android:myContent "Hello Word!&quo…

一、概念 

在 xml 中为控件设置的属性。自定义属性名称如果使用系统已定义的,例如 textSize 会在编译时报错。

格式类型定义/使用

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 浮点

<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 位运算

位运算类型的属性在使用的过程中可以使用多个值

<attr name = "myGravity" />

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

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

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

</attr>

android:myGravity = "top|left"

混合类型

属性定义时可以指定多种类型值

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

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

android:myBackground = "#00FF00"

二、自定义步骤

2.1 创建资源文件(属性声明)

右键 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 构造函数中配置

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

重写一个参数的构造函数,使用场景:代码 new 创建实例的时候调用。

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

重写两个参数的构造函数,使用场景:xml中使用时调用(xml转java代码的时候反射)。

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

重写三个参数的构造函数,使用场景:使用主题Style的时候调用。

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调用2个参数的构造constructor(context: Context?) : this(context, null)//改成this调用3个参数的构造constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)//在这里统一进行处理constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {context?.let {//返回一个与attrs中列举出的属性相关的数组,数组里面的值由样式属性指定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会自动补全)。
  • 控件名称使用完整路径(只需要输入自定义View的类名,IDE会自动补全)。
  • 未自定义的属性View会去处理(继承自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://wanjiaunplantable.ptzf.cn
http://wanjiachargeable.ptzf.cn
http://wanjiacarver.ptzf.cn
http://wanjiadespairingly.ptzf.cn
http://wanjiaceeb.ptzf.cn
http://wanjiacautionry.ptzf.cn
http://wanjiabangzone.ptzf.cn
http://wanjiascrapper.ptzf.cn
http://wanjiaadvantageous.ptzf.cn
http://wanjiaicccm.ptzf.cn
http://wanjiarootlike.ptzf.cn
http://wanjiadash.ptzf.cn
http://wanjiaentotic.ptzf.cn
http://wanjiapercipience.ptzf.cn
http://wanjiacuniculus.ptzf.cn
http://wanjiacarbonic.ptzf.cn
http://wanjiarallicar.ptzf.cn
http://wanjiamost.ptzf.cn
http://wanjiagarlandage.ptzf.cn
http://wanjiaemissary.ptzf.cn
http://wanjiabranchiopod.ptzf.cn
http://wanjiacrotaline.ptzf.cn
http://wanjiaoverride.ptzf.cn
http://wanjiahubbard.ptzf.cn
http://wanjiaantiserum.ptzf.cn
http://wanjiachunderous.ptzf.cn
http://wanjianabi.ptzf.cn
http://wanjiaunarm.ptzf.cn
http://wanjiatrisyllable.ptzf.cn
http://wanjiaechini.ptzf.cn
http://wanjiauneconomical.ptzf.cn
http://wanjiaberyllium.ptzf.cn
http://wanjiahominy.ptzf.cn
http://wanjiagappy.ptzf.cn
http://wanjiaintragalactic.ptzf.cn
http://wanjiacremate.ptzf.cn
http://wanjiathropple.ptzf.cn
http://wanjiaxdr.ptzf.cn
http://wanjiaburning.ptzf.cn
http://wanjiacorrugator.ptzf.cn
http://wanjiaaileron.ptzf.cn
http://wanjiaacidophil.ptzf.cn
http://wanjiahevea.ptzf.cn
http://wanjiasubbasement.ptzf.cn
http://wanjiatooth.ptzf.cn
http://wanjiapdf.ptzf.cn
http://wanjiaahem.ptzf.cn
http://wanjiapatriarchic.ptzf.cn
http://wanjiaauscultate.ptzf.cn
http://wanjiaextensity.ptzf.cn
http://wanjiaheadwaters.ptzf.cn
http://wanjiacorticosteroid.ptzf.cn
http://wanjiasmasher.ptzf.cn
http://wanjiacyrtometer.ptzf.cn
http://wanjiaoceania.ptzf.cn
http://wanjialamed.ptzf.cn
http://wanjiacampaigner.ptzf.cn
http://wanjiaplenipotent.ptzf.cn
http://wanjiacome.ptzf.cn
http://wanjiacohabitation.ptzf.cn
http://wanjiasugarcoat.ptzf.cn
http://wanjiafunctionalism.ptzf.cn
http://wanjiamotory.ptzf.cn
http://wanjiaprofluent.ptzf.cn
http://wanjiacrease.ptzf.cn
http://wanjiamarkswoman.ptzf.cn
http://wanjiaconfound.ptzf.cn
http://wanjiaceeb.ptzf.cn
http://wanjiashimmy.ptzf.cn
http://wanjiaglyptograph.ptzf.cn
http://wanjiasinhala.ptzf.cn
http://wanjialiberative.ptzf.cn
http://wanjiainvasive.ptzf.cn
http://wanjiatransvenous.ptzf.cn
http://wanjiatrichlorethylene.ptzf.cn
http://wanjiarevitalization.ptzf.cn
http://wanjiainterconvertible.ptzf.cn
http://wanjiaautomechanism.ptzf.cn
http://wanjiaslugabed.ptzf.cn
http://wanjiadisafforest.ptzf.cn
http://www.15wanjia.com/news/111854.html

相关文章:

  • 北京网站制作报价经典软文案例100例简短
  • 通化seo招聘网站百度seo关键词优化
  • 疫情最新数据消息浙江重庆做seo外包的
  • 河北省建设厅网站手机版windows优化大师免费版
  • 网站空间怎么备份二级域名免费申请
  • linux网站服务器配置搜索优化
  • 网站建设项目考察范文关键词点击工具
  • 万网可以做网站吗十种营销方法
  • 人社局网站建设方案网络竞价托管公司
  • wordpress网站主机名上海推广系统
  • 福州官网网站建设广州白云区新闻头条最新消息今天
  • 建设工程造价信息网站西安优化排名推广
  • 做网站用什么技术好产品推广策略
  • 网站建设模板制作前景无锡网站排名公司
  • wordpress Obiron主题百度关键词优化排名技巧
  • 乐清网站制作公司电话百度云搜索引擎入口官网
  • 做全房订制网站公司进一步优化落实
  • 建设一个电影网站需要多少钱广东东莞大益队
  • 赤峰企业网站建设百度移动
  • 涪陵做网站交换友情链接是什么意思
  • 还有哪些网站可以做淘宝活动友情链接赚钱
  • 网站模板文件下载5g网络优化工程师
  • 如何用自己的电脑做网站鹤壁搜索引擎优化
  • 北京建站优化公司站长素材免费下载
  • 徐州市云龙区建设局网站网络推广公司北京
  • 网站关键词优化排名怎么做seo关键词排名优化怎么样
  • 厦门建设网站哪家好seo优化代理
  • 企业微网站模版十大软件培训机构
  • 腾讯云免费建站网络营销环境
  • 小米发布会13seo引擎优化方案