Android_RadioGroup实现Tab
来源:互联网 发布:柏拉图表软件 编辑:程序博客网 时间:2024/06/16 09:00
效果图:
代码:
一.布局文件
android:button="@null" 设置RadioGroup的圆圈消失
android:drawableTop="@android:drawable/btn_star" 设置图片在文字的上面
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="#006644" > <RadioGroup android:id="@+id/rg" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:id="@+id/rb_message" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:button="@null" android:checked="true" android:drawableTop="@android:drawable/btn_star" android:gravity="center" android:text="消息" /> <RadioButton android:id="@+id/rb_contact" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:button="@null" android:drawableTop="@android:drawable/btn_star" android:gravity="center" android:text="联系人" /> <RadioButton android:id="@+id/rb_dynamic" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:button="@null" android:drawableTop="@android:drawable/btn_star" android:gravity="center" android:text="动态" /> <RadioButton android:id="@+id/rb_setting" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:button="@null" android:drawableTop="@android:drawable/btn_star" android:gravity="center" android:text="设置" /> </RadioGroup> </LinearLayout></RelativeLayout>
二.设置按钮的选中事件监听器
package com.example.fragment;import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.RadioGroup.OnCheckedChangeListener;public class MainActivity extends Activity {protected static final String TAG = "MainActivity";private RadioGroup rg;private RadioButton rb_message;private RadioButton rb_contact;private RadioButton rb_dynamic;private RadioButton rb_setting;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);init();// RadioGroup的点击事件rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup arg0, int arg1) {if (arg1 == rb_message.getId()) {Log.i(TAG, "选中了消息的按钮");} else if (arg1 == rb_contact.getId()) {Log.i(TAG, "选中了联系人的按钮");} else if (arg1 == rb_dynamic.getId()) {Log.i(TAG, "选中了动态的按钮");} else if (arg1 == rb_setting.getId()) {Log.i(TAG, "选中了设置的按钮");}}});}/** * 控件的实例化 */private void init() {rg = (RadioGroup) findViewById(R.id.rg);rb_message = (RadioButton) findViewById(R.id.rb_message);rb_contact = (RadioButton) findViewById(R.id.rb_contact);rb_dynamic = (RadioButton) findViewById(R.id.rb_dynamic);rb_setting = (RadioButton) findViewById(R.id.rb_setting);}}
0 0
- Android_RadioGroup实现Tab
- 实现回车-->Tab
- extjs实现左侧tab
- JavaScript实现的tab
- javascript 实现Tab滑动
- 实现Tab样式功能
- Jquery实现Tab效果
- Tab页用CSS3实现
- Tab动画滑动实现
- android tab的实现
- gallery实现tab
- android实现tab功能
- div+CSS实现tab
- HTML tab页 实现
- fragment实现android tab
- Fragment实现tab功能
- ActionBar实现Tab导航
- 使用fragment实现tab
- 使UItableViewCell 变为可删除状态
- UVA 537 字符串中的公式计算字母识别
- LINE22 中断
- 使用SAX方式生成XML文档
- 根据控件名称查找控件
- Android_RadioGroup实现Tab
- C和C++混合编程(error C2059: syntax error : 'string')
- jqgrid单元格内容过长 样式处理
- jbrowse中配置左边菜单的解决方法
- 使用Struts2和jQuery EasyUI实现简单CRUD系统(二)——ajax与struts2的交互
- Thymeleaf基本知识
- hdu 5443 The Water Problem 2015 ACM/ICPC Asia Regional Changchun Online
- Android activity和fragment异步传输数据的问题
- Java线程:并发协作-生产者消费者模型