4.基本控件 Button

 

 

<!-- 有时候我们的background不好使,老版本好用,这时候就需要我们去style.xml改点东西了-->
更改一下这东西即可

 

 

 

 

 

 

好的现在背景颜色好用了,我又增加了个需求,按下和松手的颜色要不一致,咋办???

我们可以新建一个在drawable文件夹下新建一个Drawable resources file  选择selector

 

 

 选择好了之后,我们想让button的背景点击和按下不同,所以我们在res资源文件夹下新建个vector asset 矢量图

 

 这里我们选择一个飞机,点击确定过后就会在drawable文件夹下新出来一个文件

 

按照此法,我们再新建个加油站

然后在btn_selector.xml中写按下和松手的item

 

 

然后在Button的背景中引入

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

   <Button
       android:background="@drawable/brn_selector"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"/>

</LinearLayout>

 

当然了现在的飞机和加油站都是黑色的,给他俩换颜色也是可以的,新建一个颜色选择器,在res下面新建一个color文件,在这文件里新建一个color resource

 

 

 

 

 

 

 

posted @ 2021-09-04 14:12  涂妖教  阅读(98)  评论(0)    收藏  举报