页面设计
相关代码
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();
}
}
});
}