MaiActivity:xml布局
<FrameLayout android:id="@+id/fram_layout" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="8.5"> </FrameLayout> <RadioGroup android:id="@+id/rg" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1.5" android:orientation="horizontal"> <RadioButton android:id="@+id/rbtn1" android:layout_width="0dp" android:layout_height="match_parent" android:button="@null" android:checked="true" android:text="首页" android:drawableTop="@drawable/img_selector" android:layout_weight="1" android:gravity="center" /> <RadioButton android:id="@+id/rbtn2" android:layout_width="0dp" android:layout_height="match_parent" android:button="@null" android:drawableTop="@drawable/img_yaowen" android:text="发现" android:layout_weight="1" android:gravity="center" /> <RadioButton android:id="@+id/rbtn3" android:layout_width="0dp" android:layout_height="match_parent" android:button="@null" android:drawableTop="@drawable/img_login" android:text="登录" android:layout_weight="1" android:gravity="center" /> </RadioGroup>
selector选择器
drawable目录下
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/user_1"/> <item android:state_checked="false" android:drawable="@drawable/user_0"/> <item android:drawable="@drawable/user_0"/> </selector>
其余三个同理
xml布局
<EditText android:layout_width="match_parent" android:layout_height="30dp" android:textSize="14dp" android:layout_gravity="center_vertical" android:background="@drawable/shape_stly" android:hint="在线泡水|两个萌娃|荒岛惊魂"/> </LinearLayout>
EditText用shape的样式
shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#fff" ></solid> <corners android:radius="10dp"/> <stroke android:color="#000" android:width="1dp"/> </shape>
java代码
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); frameLayout = (FrameLayout) findViewById(R.id.fram_layout); radioGroup = (RadioGroup) findViewById(R.id.rg); //默认显示第一页 getSupportFragmentManager().beginTransaction().replace(R.id.fram_layout,new HomeFragment()).commit(); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) { switch (i){ case R.id.rbtn1: getSupportFragmentManager().beginTransaction().replace(R.id.fram_layout,new HomeFragment()).commit(); break; case R.id.rbtn2: getSupportFragmentManager().beginTransaction().replace(R.id.fram_layout,new YaowenFragment()).commit(); break; case R.id.rbtn3: getSupportFragmentManager().beginTransaction().replace(R.id.fram_layout,new LoginFragment()).commit(); break; default: break; } } }); }