radiogroup中radiobutton实现activity跳转

radiogroup中radiobutton实现activity跳转

页面设计

相关代码

nav_bottom.xml

<RadioGroup
        android:id="@+id/rg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_anchor="@+id/view_pager2"
        app:layout_anchorGravity="start|bottom"
        android:background="@color/white"
        android:orientation="horizontal">
        <RadioButton
            android:id="@+id/rb_zhu"
            style="@style/radiobutton_style"
            android:checked="true"
            android:drawableTop="@drawable/ic_home"
            android:text="首页"/>
        <RadioButton
            android:id="@+id/rb_storefront"
            style="@style/radiobutton_style"
            android:checked="true"
            android:drawableTop="@drawable/ic_storefront"
            android:text="商城"/>
        <RadioButton
            android:id="@+id/rb_message"
            style="@style/radiobutton_style"
            android:checked="true"
            android:drawableTop="@drawable/ic_message"
            android:text="消息"/>
        <RadioButton
            android:id="@+id/rb_home"
            style="@style/radiobutton_style"
            android:checked="true"
            android:drawableTop="@drawable/ic_person"
            android:text="我"/>

    </RadioGroup>

效果图

nav_bottom.xml效果图

在这里插入图片描述

页面展示图

在这里插入图片描述

逻辑展示

private RadioGroup mradioGroup;

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        mradioGroup = findViewById(R.id.rg);
        mradioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                int checkedID = radioGroup.getCheckedRadioButtonId();
                if (checkedID==R.id.rb_zhu){
                    Intent intent = new Intent();
                    intent.setClass(MainActivity.this,MainActivity.class);
                    startActivity(intent);
                    System.out.println("ID值="+radioGroup.getCheckedRadioButtonId());
                    finish();
                }
                if (checkedID==R.id.rb_storefront){
                    Intent intent = new Intent();
                    intent.setClass(MainActivity.this,ChatActivity.class);
                    startActivity(intent);
                    System.out.println("ID值="+radioGroup.getCheckedRadioButtonId());
                    finish();
                }
                if (checkedID==R.id.rb_message) {
                    Intent intent = new Intent();
                    intent.setClass(MainActivity.this,ChatActivity.class);
                    startActivity(intent);
                    System.out.println("ID值="+radioGroup.getCheckedRadioButtonId());
                    finish();
                }
                if (checkedID==R.id.rb_home){
                    Intent intent = new Intent();
                    intent.setClass(MainActivity.this,ChatActivity.class);
                    startActivity(intent);
                    System.out.println("ID值="+radioGroup.getCheckedRadioButtonId());
                    finish();
                }
            }
        });
        }

效果展示

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值