The Android implementation of the bottom sliding menu of Meituan APP is for your reference. The specific content is as follows
In the current APP applications, there are many applications similar to the bottom sliding menu of Meituan APP, such as QQ, WeChat, and Alipay. The development process is as follows
1. Bottom button
The bottom button uses RadioButton.
// Button layout<LinearLayout android: android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true"> <RadioGroup android: android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <RadioButton android: style="@style/RadioButton" android:checked="true" android:drawableTop="@drawable/home" android:text="front page" /> <RadioButton android: style="@style/RadioButton" android:drawableTop="@drawable/investment" android:text="invest" /> <RadioButton android: style="@style/RadioButton" android:drawableTop="@drawable/shooting" android:text="Paipa" /> <RadioButton android: style="@style/RadioButton" android:drawableTop="@drawable/recom_member" android:text="mine" /> <RadioButton android: style="@style/RadioButton" android:drawableTop="@drawable/more" android:text="More" /> </RadioGroup>
// style style<style name="RadioButton"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">60dp</item> <item name="android:gravity">center</item> <item name="android:layout_weight">1</item> <item name="android:button">@null</item> <item name="android:background">@drawable/menueselector</item> </style>
Menueselector in style style is the background selector, so that the button selection changes color
Create a new folder (drawable-nodpi) in the Res directory, create a new xml file, select the selector with the resource type Drawable, and create item options in each selector
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:andro> <!--Select the background color--> <item android:drawable="@color/checked" android:state_checked="true" /> <!--未Select the background color--> <item android:drawable="@color/nochecked" android:state_checked="false" /> </selector>
2. Sliding window in the middle
<. android: android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/llradiogroup"> </.>
3. Add the corresponding Fragment to the sliding window and listen to the corresponding events
Pay attention to two points in the following code
- MainActivity must be inherited from FragmentActivity, so that you can find the getSupportFragmentManager() method.
- When writing Fragment, remember to introduce ., not (it was introduced in 3.0, and is preferred for compatibility with lower versions.)
package ; import .; import ; import .; import .; import .; import .; import ; import ; import ; import ; import ; import ; import ; import ; import ; import ; public class MainActivity extends FragmentActivity { // HomeFragmentIndex private static final int HomeViewPagerIndex = 0; // InvestmentFragmentIndex private static final int InvsetViewPagerIndex = 1; // CaptureFragmentIndex private static final int CaptureViewPagerIndex = 2; // MyFragmentIndex private static final int MyViewPagerIndex = 3; // MoreFragmentIndex private static final int MoreViewPagerIndex = 4; private ViewPager viewPager; // Home page private HomeFragment homeFragment; // Investment page private InvestmentFragment investmentFragment; //Photo page private CaptureFragment captureFragment; // My page private MyFragment myFragment; // More pages private MoreFragment moreFragment; // Fragment collection private List<Fragment> fragmentList; // FragmentAdapter private MyPageFramgentAdapter myPageFramgentAdapter; // Menu RadioGroup private RadioGroup radioGroup; // Home page button private RadioButton rbtnHome; // Investing Button private RadioButton rbtnInvest; // Photo button private RadioButton rbtnCapture; // My button private RadioButton rbtnMine; // More buttons private RadioButton rbtnMore; @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); setContentView(.activity_main); initViews(); } private void initViews() { viewPager = (ViewPager) findViewById(); homeFragment = new HomeFragment(); investmentFragment = new InvestmentFragment(); captureFragment = new CaptureFragment(); myFragment = new MyFragment(); moreFragment = new MoreFragment(); fragmentList = new ArrayList<Fragment>(); radioGroup = (RadioGroup) findViewById(.rg_menu); rbtnHome = (RadioButton) findViewById(.rbtn_home); rbtnInvest = (RadioButton) findViewById(.rbtn_vest); rbtnCapture = (RadioButton) findViewById(.rbtn_photo); rbtnMine = (RadioButton) findViewById(.rbtn_mine); rbtnMore = (RadioButton) findViewById(.rbtn_more); // Select the button and viewPager displays the corresponding page (new () { @Override public void onCheckedChanged(RadioGroup radioGroup, int i) { switch (i) { case .rbtn_home: (HomeViewPagerIndex); break; case .rbtn_vest: (InvsetViewPagerIndex); break; case .rbtn_photo: (CaptureViewPagerIndex); break; case .rbtn_mine: (MyViewPagerIndex); break; case .rbtn_more: (MoreViewPagerIndex); break; } } }); //Add Fragment to the collection (homeFragment); (investmentFragment); (captureFragment); (myFragment); (moreFragment); FragmentManager fm = getSupportFragmentManager(); myPageFramgentAdapter = new MyPageFramgentAdapter(fm); (myPageFramgentAdapter); // The viewPager has changed, and the corresponding button status becomes selected (new () { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { switch (position) { case HomeViewPagerIndex: (true); break; case InvsetViewPagerIndex: (true); break; case CaptureViewPagerIndex: (true); break; case MyViewPagerIndex: (true); break; case MoreViewPagerIndex: (true); break; default: break; } } @Override public void onPageScrollStateChanged(int state) { } }); } // Adapters required by viewPager class MyPageFramgentAdapter extends FragmentPagerAdapter { public MyPageFramgentAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { return (position); } @Override public int getCount() { return (); } } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.