//actvity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="app.jiyun.com.android_yindao_demo.MainActivity">
<android.support.v4.view.ViewPager
android:id="@+id/ViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"></android.support.v4.view.ViewPager>
<RadioGroup
android:id="@+id/RadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/Radio_one"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/radio_style"
android:button="@null" />
<RadioButton
android:id="@+id/Radio_Two"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/radio_style"
android:button="@null" />
<RadioButton
android:id="@+id/Radio_Three"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/radio_style"
android:button="@null" />
</RadioGroup>
</RelativeLayout>
//radio_style的xml详细设置
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
//被点击(按压)的时候
<item android:drawable="@drawable/radio_shape" android:state_pressed="true" />
//被选中的时候
<item android:drawable="@drawable/radio_shape" android:state_checked="true" />
//被聚焦的时候
<item android:drawable="@drawable/radio_shape" android:state_focused="true" />
//默认
<item android:drawable="@drawable/radio_no_shape" />
</selector>
//按钮的shape设置
(1)<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="15dp" />
<solid android:color="@color/colorPrimary" />
</shape>
(2)<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="15dp" />
<solid android:color="@color/colorAccent" />
</shape>
//主界面的Java代码
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ViewPager ViewPager;
private RadioGroup RadioGroup;
private ArrayList<View> mList = new ArrayList<>();
private Button mBtn;
private SharedPreferences mShare;
private SharedPreferences.Editor mEditor;
private Context mContext = MainActivity.this;
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
mShare = mContext.getSharedPreferences("user",MODE_PRIVATE);
//编辑器
mEditor = mShare.edit();
boolean isTrue = mShare.getBoolean("isTrue", false);
if (isTrue){
Intent intent = new Intent(MainActivity.this, TestActivity.class);
startActivity(intent);
finish();
}
initView();
}
private void initView() {
ViewPager = (ViewPager) findViewById(R.id.ViewPager);
RadioGroup = (RadioGroup) findViewById(R.id.RadioGroup);
View one = getLayoutInflater().inflate(R.layout.view_one, null);
View two = getLayoutInflater().inflate(R.layout.view_two, null);
View three = getLayoutInflater().inflate(R.layout.view_three, null);
mBtn = (Button) three.findViewById(R.id.ViewThree_Btn);
mBtn.setOnClickListener(this);
mList.add(one);
mList.add(two);
mList.add(three);
MyViewPagerAdapter myViewPagerAdapter = new MyViewPagerAdapter(mList);
ViewPager.setAdapter(myViewPagerAdapter);
RadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.Radio_one:
ViewPager.setCurrentItem(0);
break;
case R.id.Radio_Two:
ViewPager.setCurrentItem(1);
break;
case R.id.Radio_Three:
ViewPager.setCurrentItem(2);
break;
}
}
});
ViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
RadioButton rb = (RadioButton) RadioGroup.getChildAt(position);
rb.setChecked(true);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.ViewThree_Btn:
mEditor.putBoolean("isTrue",true);
mEditor.commit();
Intent intent = new Intent(MainActivity.this, TestActivity.class);
startActivity(intent);
finish();
break;
}
}
}