<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.yuekaomoni_99.MainActivity">


<RadioGroup
android:layout_width="match_parent"
android:background="#f00"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:id="@+id/rg">
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/rb_index"
android:checked="true"
android:layout_weight="1"
android:text="首页"

android:button="@null"
android:gravity="center"/>

<!--文字颜色的改变 1.res新建一个color文件夹 2.color文件夹内 新建selector,<item android:color="" 3.radiobutton的属性 android:textColor=@color/....>-->
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/rb_mind"
android:layout_weight="1"
android:gravity="center"
android:text="想法"

android:button="@null"/>

</RadioGroup>

<FrameLayout

android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fcontent"
></FrameLayout>


</RelativeLayout>




------------------------------------------------------------------------------------------------------------










import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;


public class MainActivity extends AppCompatActivity {

private FrameLayout fcontent;
private RadioButton rb_index;
private RadioButton rb_main;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fcontent = findViewById(R.id.fcontent);
RadioGroup radioGroup=findViewById(R.id.rg);
rb_index = findViewById(R.id.rb_index);
rb_main = findViewById(R.id.rb_mind);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i){
case R.id.rb_index:
getSupportFragmentManager().beginTransaction().replace(R.id.fcontent,new Fragment_01()).commit();
break;
case R.id.rb_mind:
getSupportFragmentManager().beginTransaction().replace(R.id.fcontent,new MindFragment()).commit();
break;
}
}
});

//设置初始fragment页面
getSupportFragmentManager().beginTransaction().
replace(R.id.fcontent,new Fragment_01()).commit();


}}