zoukankan      html  css  js  c++  java
  • 高仿拉手网底部菜单实现FragmentActivity+Fragment+RadioGroup

    先把欢迎页和引导页的代码上传了http://download.csdn.net/detail/u013134391/7183787不要积分的。

    底部菜单条实如今4.0曾经都是用tabhost。如今基本都被fargmentActivity加RadioGroup替代。以下实现底部菜单相同是用后者实现。

    先声明一组四个的RadioButton的RadioGroup的单选button组,然后呢对照拉手网我们就发现样子太不一样了,我们的另一个单选button的样式,这个我们写RadioButton的android:button="@null"属性去除样式。

    另外拉手网的是上面图片以下是名称的样式,并且他的名城和图片在不通状态下颜色不同,这个就须要我们写几个button选择器selector,我们通过selector的不通状态来设置不通的图片。名称也是一样。再设置RadioButton设置他的android:drawableTop=""属性,这样图片就会在字的上面了。这样我们的底部菜单条的布局就写完了。

    在我们点击底部的单选button的时候怎么切换,在我们刚刚写的底部菜单的布局上加入一个FramentLayout,占领除了底部菜单条的全部地方。

    然后在主界面里,监听RadioGroup的切换,监听checkedChanged,以下我们准备4个Fragmenet的切换界面。这里的Fragment由于要向下兼容,所以我们使用的是扩展包里的Fragment,Fragment重写onCreateView方法,载入布局文件。
    我们须要写一个adapter来帮我们管理这四个界面的切换,这里的adapter我们就写的是FragmentStatePagerAdapter,这里构造方法须要传入參数FragmentManager,全部我们的MainActivity须要继承的是FragmentActivity,这样才干this.getSupportFragmentManager()获取一个FragmentManager,这里须要必要实现getcount,由于我们就4个界面就直接写4。getItem这里我们用来初始化界面,推断当前是那个界面0就是主页了,其它以此类推。然后在RadioGroup监听的地方使用FrameLayout替换进行界面的替换//详细代码例如以下

    //将frameLayout替换成第index个Fragment
                    Fragment fragment = (Fragment) fragmentAdapter.instantiateItem(
                            frameLayout, index);
                    //将第index个界面替换成fragment
                    fragmentAdapter.setPrimaryItem(frameLayout, index, fragment);
                    //提交
    
    fragmentAdapter.finishUpdate(frameLayout);
    http://download.csdn.net/detail/u013134391/7190025  代码无积分下载

  • 相关阅读:
    Codeforces 1485C Floor and Mod (枚举)
    CodeForces 1195D Submarine in the Rybinsk Sea (算贡献)
    CodeForces 1195C Basketball Exercise (线性DP)
    2021年初寒假训练第24场 B. 庆功会(搜索)
    任务分配(dp)
    开发工具的异常现象
    Telink MESH SDK 如何使用PWM
    Telink BLE MESH PWM波的小结
    [LeetCode] 1586. Binary Search Tree Iterator II
    [LeetCode] 1288. Remove Covered Intervals
  • 原文地址:https://www.cnblogs.com/mfrbuaa/p/5246764.html
Copyright © 2011-2022 走看看