在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>