BackGround内外两种,Selector简用,App底部按钮=Selector背景选择器

在android中,给相应的布局设置背景图片有两种方法


第一,在布局中
即在相应布局中使用以下属性
android:background="@drawable/bg"   ///在资源文件中添加自己想要的背景图片 在此引用即可
 
第二,在代码中实现,如下
LinearLayout layout = (LinearLayout)this.findViewById(R.id.mylayout);
layout.setBackgroundResource(R.drawable.bg);

实现App界面底部功能栏按钮 

 

//首先先上一个效果图(选中变色):                图片:           

先准备两张图片然后在drawable下创建selector,创建item设置选中状态和非选中状态;

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/start_true" android:state_checked="true"></item>
    <item android:drawable="@drawable/start_false" android:state_checked="false"></item>

</selector>

   selector中各种状态选择,选择最适合你的那个 :

 

接下来式layout布局写法:

创建RadioGroup控件-->
子控件RadioButton:加权重,图片位于top方,调用写好的Selector,按钮设置为@null,最后gravity:center

 <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/radio0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:drawableTop="@drawable/btu_seletor"
            android:gravity="center"
            android:text="首页" />

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:drawableTop="@drawable/btu_seletor"
            android:gravity="center"
            android:text="视频" />

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:drawableTop="@drawable/btu_seletor"
            android:gravity="center"
            android:text="服务" />

        <RadioButton
            android:id="@+id/radio3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:button="@null"
            android:drawableTop="@drawable/btu_seletor"
            android:gravity="center"
            android:text="我的" />
    </RadioGroup>

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值