有没有详细讲解安卓XML的书

谁学逆向工程 谁学逆向工程 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
照书做了一段时间的例子,刚适应了各种 Layout 中嵌套各种控件(Button TextView)。
今天继续做例子,发现XML中除了控件以外还有其他“关键字”,比如下面的“selector” 和 “item”,这是什么意思,哪里来的

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/root"
android:orientation="vertical">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文字带阴影的按钮"
android:textSize="12pt"
android:shadowColor="#aa5"
android:shadowRadius="1"
android:shadowDx="5"
android:shadowDy="5" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="普通按钮"
android:id="@+id/button"
android:background="@drawable/red"
android:textSize="10pt" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="带文字的图片按钮"
android:id="@+id/button2"
android:background="@drawable/button_selector"
android:textSize="11px" />


</LinearLayout>

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true"
android:drawable="@drawable/red"/>
<item android:state_pressed="false"
android:drawable="@drawable/purple"/>
</selector>

绿色按钮按下的时候变成红色,松开的时候恢复绿色
...全文
评论 11
收藏 已收藏
分享
返回顶部
谁学逆向工程
Android 80,489 成员 91,375 内容