RadioButton 做一个带图片的底部导航栏
程序员文章站
2022-07-04 09:40:59
废话不多说直接上代码:
废话不多说先看图,然后直接上代码:
这个图是底部菜单栏, 他的上面是一个frameLayout帧布局(请选择性忽略)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
tools:context=".app.MainActivity">
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RadioGroup
android:id="@+id/rg_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/home_bottom_parent_bg"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rb_home"
style="@style/MainButtonStyle"
android:drawableTop="@drawable/home_button_selector"
android:text="首页" />
<RadioButton
android:id="@+id/rb_type"
style="@style/MainButtonStyle"
android:drawableTop="@drawable/type_button_selector"
android:text="分类" />
<RadioButton
android:id="@+id/rb_community"
style="@style/MainButtonStyle"
android:drawableTop="@drawable/community_button_selector"
android:paddingTop="10dp"
android:text="发现" />
<RadioButton
android:id="@+id/rb_cart"
style="@style/MainButtonStyle"
android:drawableTop="@drawable/cart_button_selector"
android:text="购物车" />
<RadioButton
android:id="@+id/rb_user"
style="@style/MainButtonStyle"
android:drawableTop="@drawable/user_button_selector"
android:text="个人中心" />
</RadioGroup>
</LinearLayout>
下面这个是写在资源文件里的 style
<style name="MainButtonStyle">
<!-- Customize your theme here. -->
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_weight">1</item>
<item name="android:button">@null</item>
<!-- <item name="android:drawablePadding">3dp</item>-->
<item name="android:textColor">@drawable/bottom_button_text_selector</item>
<item name="android:textSize">10sp</item>
<item name="android:gravity">center</item>
</style>
很简单吧 直接复制粘贴即可 (多动手才是学习的王道)
本文地址:https://blog.csdn.net/qq_31020171/article/details/108986470