一切为了快速开发
开发类似界面
背景:
文字颜色:
开发类似界面
import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.view.View; import android.widget.RadioButton; import com.yirui.youbao.App; import com.yirui.youbao.fragment.ParkingPayedListFragment; import com.yirui.youbao.fragment.ParkingUnpayListFragment; /** * * @author pythoner * */ public class ParkingPayActivity extends BaseActivity implements View.OnClickListener{ private final int count = 2;//页数 private int curPosition=0;//当前页 private RadioButton[] rbs; private ViewPager viewPager; private FragmentPagerAdapter pagerAdapter; private Fragment[] fragments; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_parking_pay); initActionBar("App付费"); initViews(); } private void initViews() { initIndicator(); initViewPager(); } private void initIndicator(){ rbs = new RadioButton[count]; rbs[0] = (RadioButton) findViewById(R.id.rb_0); rbs[1] = (RadioButton) findViewById(R.id.rb_1); for (int i = 0; i < rbs.length; i++) { rbs[i].setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String tag = (String) v.getTag(); curPosition=Integer.parseInt(tag); viewPager.setCurrentItem(curPosition); } }); } rbs[curPosition].setChecked(true); } private void initViewPager(){ fragments = new Fragment[count]; fragments[0] = ParkingUnpayListFragment.newInstance(); fragments[1] = ParkingPayedListFragment.newInstance(); pagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public int getCount() { return fragments.length; } @Override public Fragment getItem(int position) { return fragments[position]; } }; viewPager = (ViewPager) findViewById(R.id.viewPager); viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { // TODO Auto-generated method stub rbs[position].setChecked(true); curPosition=position; } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub } @Override public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub } }); viewPager.setAdapter(pagerAdapter); viewPager.setCurrentItem(curPosition); } @Override public void onClick(View v) { // TODO Auto-generated method stub } }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/bg_gray" android:orientation="vertical" > <include layout="@layout/actionbar_comm" /> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" android:padding="8dp" > <RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:orientation="horizontal" > <RadioButton android:id="@+id/rb_0" android:tag="0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bg_blue_trans_with_frame" android:button="@null" android:paddingBottom="4dp" android:paddingLeft="8dp" android:paddingRight="8dp" android:paddingTop="4dp" android:text="未付费" android:textColor="@color/textcolor_blue_white_radio" /> <RadioButton android:id="@+id/rb_1" android:tag="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bg_blue_trans_with_frame" android:button="@null" android:paddingBottom="4dp" android:paddingLeft="8dp" android:paddingRight="8dp" android:paddingTop="4dp" android:text="已付费" android:textColor="@color/textcolor_blue_white_radio" /> </RadioGroup> </FrameLayout> <android.support.v4.view.ViewPager android:id="@+id/viewPager" android:layout_width="match_parent" android:layout_height="match_parent" android:flipInterval="30" android:background="@android:color/white" android:layout_marginTop="16dp" android:persistentDrawingCache="animation" /> </LinearLayout>
背景:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true"> <shape> <solid android:color="@color/primary" /> <stroke android:width="1dp" android:color="@color/primary" /> <corners android:topLeftRadius="dp" android:topRightRadius="0dp" android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/> </shape> </item> <item> <shape> <solid android:color="@android:color/transparent" /> <stroke android:width="1dp" android:color="@color/primary" /> <corners android:topLeftRadius="dp" android:topRightRadius="0dp" android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/> </shape> </item> </selector>
文字颜色:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="true" android:color="@android:color/white" /> <item android:color="@color/primary" /> </selector>