首页 > 其他分享 >直播系统搭建,Android使用RadioGroup+RadioButton实现导航栏

直播系统搭建,Android使用RadioGroup+RadioButton实现导航栏

时间:2023-03-27 14:23:53浏览次数:104  
标签:layout RadioButton RadioGroup test bar Android navigation id android

直播系统搭建,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

相关文章

  • 2012第30周国内Android应用下载动态
    本周榜单共包含安卓市场、安智市场、应用汇等在内的13家第三方应用商店以及GooglePlay官方市场中国区共14家Android市场应用下载排行数据,其中安卓市场、91手机助手、腾讯......
  • iOS经典游戏《疯狂喷气机》全球中文Android版正式发布
    这是世界顶级手机游戏开发商首次在全球版本中加入国内手机游戏平台,拉开了中国手机游戏领域与世界接轨的序幕。届时,各国版本中都包含乐逗平台,让全球玩家更便捷地交流互动,......
  • HTC将在9月19日召开发布会,可能发布更便宜的Android或Windows Phone 8手机
    八月末到九月这段时间可以说是非常热闹,各大手机厂商扎堆发布新品,一时间百花齐放。之前已经得到消息,摩托罗拉、诺基亚、亚马逊、苹果、RIM等厂商将会先后在接下来的九月里召......
  • Android系统服务DropBoxManagerService详解与实践应用
     作者:vivo互联网客户端团队-MaLian借助系统DropBoxManagerService对于系统文件目录dropbox管理的设计,了解其文件管理的规则、运行机制、读写机制、管控机制,根据其......
  • 京东金融Android瘦身探索与实践
    作者:京东科技冯建华一、背景随着业务不断迭代更新,App的大小也在快速增加,2019年~2022年期间一度超过了117M,期间我们也做了部分优化如图1红色部分所示,但在做优化的同时面临着......
  • 京东金融Android瘦身探索与实践
    作者:京东科技冯建华一、背景随着业务不断迭代更新,App的大小也在快速增加,2019年~2022年期间一度超过了117M,期间我们也做了部分优化如图1红色部分所示,但在做优化的同时面......
  • 【Android】关于去标题栏 | 有的时候代码有效有的时候无效
    原因就在于你的manifest.xml的theme指向谁?  一开始我的theme指向这个↑,所以就改了好多也没用之后改成这个↓就好了 ......
  • 3.26web和android端地铁查询开发学习总结
    web端的思想在前面已经写了,Android端的思想跟web端差不多少,其中不一样的就是连接MySQL数据库,其要求的jar包是5版本左右的,而且还涉及到线程的问题,在连接MySQL的时候要另外启......
  • 3.26全部完成android和web端的地铁查询系统
    web端的思想在前面已经写了,Android端的思想跟web端差不多少,其中不一样的就是连接MySQL数据库,其要求的jar包是5版本左右的,而且还涉及到线程的问题,在连接MySQL的时候要另......
  • Android简单集成高德地图API
    首先进入高德官网  高德开放平台|高德地图API(amap.com)  注册登录完成之后创建新应用  点击之后呈现如下页面:  Key的名称随便起,主要是提交后会有一个......