Android中使用RadioButton实现QQ底部图片切换
来源:互联网 发布:xp画图软件 编辑:程序博客网 时间:2024/06/05 02:15
使用xml进行切换,在layout中线写好布局,
然后桌布实现效果。
在drawable中建立颜色筛选器的xml文件向其中添加如下代码
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" android:drawable="@drawable/a2"></item>
<item android:state_checked="false" android:drawable="@drawable/a1"></item>
</selector>
此代码实现了颜色的click事件true或者false进行颜色切换,然后在布局代码中将筛选器作为图片
<?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:orientation="vertical" >
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:id="@+id/co">
<View android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/col"
android:background="#000"/>
</LinearLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ccc"/>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioGroup android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/r"
android:orientation="horizontal">
<RadioButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="消息"
android:button="@null"
android:id="@+id/r1"
android:layout_gravity="center_horizontal"
android:drawableTop="@drawable/picture" //其中picture为图片筛选器的xml文件
android:checked="true"
android:gravity="center_horizontal"
android:layout_weight="1"/>
<RadioButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/picture1"
android:text="联系人"
android:button="@null"
android:id="@+id/r2"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_weight="1"/>
<RadioButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/picture2"
android:text="动态"
android:button="@null"
android:id="@+id/r3"
android:gravity="center_horizontal"
android:layout_weight="1"/>
</RadioGroup>
</LinearLayout>
</LinearLayout>
如此则实现了此功能
使用java代码实现
首先要在oncreate中监听radiobutton是否checked为true
RadioGroup rg=(RadioGroup) findViewById(R.id.r);
rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
然后在改变图片
radiobutton = (RadioButton)findbyin(group.getchildid())//获取button
Resources res = QQActivity.this.getResources();//使用资源
Drawable myImage = res.getDrawable(R.drawable.home);//获取资源图片
button.setCompoundDrawablesWithIntrinsicBounds(null, myImage, null, null);//四个属性分别代表drawleft drawtop.......
- Android中使用RadioButton实现QQ底部图片切换
- 底部RadioButton实现Fragment切换
- 使用RadioButton自定义样式实现喜马拉雅底部的切换功能
- RadioButton实现底部切换的菜单
- 使用radiobutton实现底部导航栏
- Fragment+自定义RadioButton实现底部导航栏,仿QQ
- Android--使用RadioButton模拟底部导航栏
- android 底部tabs切换,支持多层嵌套RadioButton的RadioGroup
- android中使用回调接口实现底部菜单的切换
- Android底部菜单切换实现
- Android中Handler类的简单使用,实现图片切换
- Android中使用ViewPager实现图片的切换
- android中fragment实现底部标签页的切换
- android-RadioButton背景使用图片
- [Android] 使用 Fragment 实现底部 Tab 切换界面
- Android学习笔记:利用Tablelayout和viewpager实现防qq底部栏切换
- Android UI-实现底部切换标签之方式一 ──fragment(底部采用radioGroup+radiobutton)添加5个子fragment
- Android中使用FragmentTabHost实现底部导航
- php的tips(接口结束符问题)
- 快速排序
- 【JQuery UI】工具提示插件——tooltip
- 海思lowlevel_init.S简单分析
- 多模块的覆盖率统计
- Android中使用RadioButton实现QQ底部图片切换
- javascript
- leetcode 022 Generate Parentheses
- php实习的tips(结束符的问题)
- HDU FatMouse and Cheese (记忆化搜索+dp思想)
- [BZOJ3998][TJOI2015]弦论
- Hadoop学习三:hadoop的一些基本配置以及相关概念
- QT5 OpenGL(五,立体图形贴图)
- Python的几个文件操作小程序