主界面网络请求数据

样式xml文件:

<?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=".MainActivity">
    <FrameLayout
        android:id="@+id/home_xianshi"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="9"/>

    <RadioGroup
        android:id="@+id/home_bottom_gadio"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:layout_weight="1">

        <RadioButton
            android:id="@+id/home_bottom_btn1"
            style="@style/bottom_bar"
            android:background="@color/beijing"
            android:text="首页"
            android:textColor="@color/white"
            android:layout_width="match_parent" />
        <RadioButton
            android:id="@+id/home_bottom_btn2"
            style="@style/bottom_bar"
            android:background="@color/beijing"
            android:text="全部服务"
            android:textColor="@color/white"
            android:layout_width="match_parent" />
        <RadioButton
            android:id="@+id/home_bottom_btn3"
            style="@style/bottom_bar"
            android:background="@color/beijing"
            android:text="智慧党建"
            android:textColor="@color/white"
            android:layout_width="match_parent" />
        <RadioButton
            android:id="@+id/home_bottom_btn4"
            style="@style/bottom_bar"
            android:background="@color/beijing"
            android:text="新闻"
            android:textColor="@color/white"
            android:layout_width="match_parent" />
        <RadioButton
            android:id="@+id/home_bottom_btn5"
            style="@style/bottom_bar"
            android:background="@color/beijing"
            android:text="个人中心"
            android:textColor="@color/white"
            android:layout_width="match_parent" />

    </RadioGroup>
</LinearLayout>

底部导航栏设置自定义样式

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="bottom_bar">
        <item name="android:layout_width">0dp</item>
        <item name="android:layout_height">match_parent</item>
        <item name="android:layout_weight">1</item>
        <item name="android:button">@null</item>
        <item name="background">@drawable/home_bottom_bar</item>
        <item name="android:textColor">@drawable/home_bottom_txt</item>
        <item name="android:textSize">15sp</item>
        <item name="android:gravity">center</item>
    </style>
</resources>

在MainActivity

public class MainActivity extends AppCompatActivity {
    private FrameLayout mHomeXianshi;
    private RadioGroup mHomeBottomGadio;
    private RadioButton mHomeBottomBtn1;
    private RadioButton mHomeBottomBtn2;
    private RadioButton mHomeBottomBtn3;
    private RadioButton mHomeBottomBtn4;
    private RadioButton mHomeBottomBtn5;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
initview();
initData();
    }

    private void initData()
    {
mHomeBottomGadio.check(R.id.home_bottom_btn1);
setFragment(new FristFragment());
mHomeBottomGadio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId)
        {
            case R.id.home_bottom_btn1:
                setFragment(new FristFragment());
                break;
            case R.id.home_bottom_btn2:
                setFragment(new AllserviceFragment());
                break;
            case R.id.home_bottom_btn3:
                setFragment(new DangJianFragment());
                break;
            case R.id.home_bottom_btn4:
                setFragment(new NewsFragment());
                break;
                case R.id.home_bottom_btn5:
            setFragment(new UserFragment());
            break;

        }
    }
});
    }

    private void setFragment(Fragment fragment)
    {
        FragmentTransaction fragmentTransaction=getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.home_xianshi,fragment).commit();
    }

    private void initview()
    {
        mHomeXianshi = findViewById(R.id.home_xianshi);
        mHomeBottomGadio = findViewById(R.id.home_bottom_gadio);
        mHomeBottomBtn1 = findViewById(R.id.home_bottom_btn1);
        mHomeBottomBtn2 = findViewById(R.id.home_bottom_btn2);
        mHomeBottomBtn3 = findViewById(R.id.home_bottom_btn3);
        mHomeBottomBtn4 = findViewById(R.id.home_bottom_btn4);
        mHomeBottomBtn5 = findViewById(R.id.home_bottom_btn5);

    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值