package xieshuaikang.com.www.zhoukao1_moni_20171230.View.Activity; import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.FrameLayout; import android.widget.RadioButton; import android.widget.RadioGroup; import xieshuaikang.com.www.zhoukao1_moni_20171230.R; import xieshuaikang.com.www.zhoukao1_moni_20171230.View.Fragment.ShouYe_Fragment; public class MainActivity extends AppCompatActivity { private FrameLayout frameLayout; private RadioButton rb1; private RadioButton rb2; private RadioButton rb3; private RadioButton rb4; private RadioGroup rg; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (Build.VERSION.SDK_INT >= 21) { View decorView = getWindow().getDecorView(); int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE; decorView.setSystemUiVisibility(option); getWindow().setStatusBarColor(Color.TRANSPARENT); } ActionBar actionBar = getSupportActionBar(); actionBar.hide(); initView(); getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,new ShouYe_Fragment()).commit(); } private void initView() { frameLayout = (FrameLayout) findViewById(R.id.frameLayout); rb1 = (RadioButton) findViewById(R.id.rb1); rb2 = (RadioButton) findViewById(R.id.rb2); rb3 = (RadioButton) findViewById(R.id.rb3); rb4 = (RadioButton) findViewById(R.id.rb4); rg = (RadioGroup) findViewById(R.id.rg); rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int i) { switch (i){ case R.id.rb1: getSupportFragmentManager().beginTransaction().replace(R.id.frameLayout,new ShouYe_Fragment()).commit(); break; case R.id.rb2: break; case R.id.rb3: break; case R.id.rb4: break; } } }); } }<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context="xieshuaikang.com.www.zhoukao1_moni_20171230.View.Activity.MainActivity">
<FrameLayout
android:id="@+id/frameLayout"
android:layout_weight="9"
android:layout_width="match_parent"
android:layout_height="0dp"></FrameLayout>
<RadioGroup
android:orientation="horizontal"
android:id="@+id/rg"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<RadioButton
android:checked="true"
android:background="@drawable/selector1"
android:id="@+id/rb1"
android:layout_weight="1"
android:button="@null"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent" />
<RadioButton
android:background="@drawable/selector2"
android:id="@+id/rb2"
android:layout_weight="1"
android:button="@null"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent" />
<RadioButton
android:background="@drawable/selector4"
android:id="@+id/rb3"
android:layout_weight="1"
android:button="@null"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent" />
<RadioButton
android:background="@drawable/selector5"
android:id="@+id/rb4"
android:layout_weight="1"
android:button="@null"
android:gravity="center"
android:layout_width="0dp"
android:layout_height="match_parent" />
</RadioGroup>
</LinearLayout>