直播系统搭建,Android使用RadioGroup+RadioButton实现导航栏
主页面代码
package com.example.taobaounion.ui.activity;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioGroup;
import com.example.taobaounion.R;
import com.example.taobaounion.utils.LogUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
public class TextActivity extends Activity {
@BindView(R.id.test_navigation_bar)
public RadioGroup navigation_bar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text);
ButterKnife.bind(this);
initListener();
}
private void initListener() {
navigation_bar.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//对控件ID进行判断,执行相应的事件
switch (checkedId){
case R.id.test_home:
LogUtils.d(TextActivity.class,"首页");
break;
case R.id.test_red_packet:
LogUtils.d(TextActivity.class,"特惠");
break;
case R.id.test_select:
LogUtils.d(TextActivity.class,"精选");
break;
case R.id.test_search:
LogUtils.d(TextActivity.class,"搜索");
break;
}
}
});
}
}
主页面布局
<?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">
<RadioGroup
android:id="@+id/test_navigation_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<RadioButton
android:id="@+id/test_home"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/selector_navigation_home"
android:gravity="center"
android:checked="true"
android:text="首页"
android:textColor="@drawable/naviagation_bar_color" />
<RadioButton
android:id="@+id/test_select"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/selector_navigation_select"
android:gravity="center"
android:text="精选"
android:textColor="@drawable/naviagation_bar_color" />
<RadioButton
android:id="@+id/test_red_packet"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/selector_navigation_redpacket"
android:gravity="center"
android:text="特惠"
android:textColor="@drawable/naviagation_bar_color" />
<RadioButton
android:id="@+id/test_search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/selector_navigation_search"
android:gravity="center"
android:text="搜索"
android:textColor="@drawable/naviagation_bar_color" />
</RadioGroup>
<!--在导航栏上加一条线-->
<View
android:layout_width="wrap_content"
android:layout_height="1px"
android:layout_marginBottom="10dp"
android:background="@color/gray"
android:layout_above="@id/test_navigation_bar"
/>
</RelativeLayout>
分别对四个icon进行状态设置,选中的时候为黄色,按压的时候为灰色,默认为黑色
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--state_pressed:表示当按压的时候的变化 state_checked:表示当选中的时候-->
<item android:drawable="@mipmap/home_checked" android:state_checked="true"/>
<item android:drawable="@mipmap/home_press" android:state_pressed="true"/>
<item android:drawable="@mipmap/home_normal"/>
</selector>
以上就是 直播系统搭建,Android使用RadioGroup+RadioButton实现导航栏,更多内容欢迎关注之后的文章
标签:layout,RadioButton,RadioGroup,test,bar,Android,navigation,id,android From: https://www.cnblogs.com/yunbaomengnan/p/17261404.html