android底部导航栏点击凸起,Android实现底部导航选中凸起效果

本文介绍如何在Android应用中实现底部导航栏选中项凸起的效果。通过设置布局参数和监听点击事件,动态改变选中和未选中状态下的图片和文字颜色,实现中间条目选中时突出显示。
摘要由CSDN通过智能技术生成

最近项目底部导航栏需要做成中间的条目选中凸起,未选中不凸起的效果,自己写了个,先贴出来代码先。。

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:clipChildren="false"

>

android:id="@+id/main_content"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_above="@id/ll_bottom"

android:background="@color/white"/>

android:id="@+id/ll_bottom"

android:layout_width="match_parent"

android:layout_height="60dp"

android:layout_alignParentBottom="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:clipChildren="false"

android:orientation="horizontal">

android:id="@+id/rl1"

android:layout_width="0dp"

android:layout_height="match_parent"

android:layout_gravity="bottom"

android:layout_weight="1">

android:id="@+id/iv1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/tv1"

android:layout_centerInParent="true"

你可以使用Android的BottomNavigationView来创建底部导航栏。要创建凸起效果,你需要使用一个自定义布局来替换默认的菜单项。以下是一些步骤: 1. 创建一个自定义布局,例如一个带有凸起图标的ImageButton。 2. 在布局中设置你的图标并添加点击事件。 3. 在你的Activity中,使用setContentView()方法将你的自定义布局设置为底部导航栏的视图。 4. 使用setOnNavigationItemSelectedListener()方法来处理导航栏项的选中事件。 这是一个示例代码: ``` // 创建自定义布局 View customView = LayoutInflater.from(this).inflate(R.layout.custom_layout, null); ImageButton customButton = customView.findViewById(R.id.custom_button); // 设置导航栏视图 BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation); bottomNavigationView.addView(customView); // 处理导航栏项的选中事件 bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.menu_item1: // 处理点击事件 return true; case R.id.menu_item2: // 处理点击事件 return true; case R.id.menu_item3: // 处理点击事件 return true; case R.id.custom_button: // 处理点击事件 return true; default: return false; } } }); ``` 请注意,你需要在自定义布局中为ImageButton添加一个唯一的ID,并在setOnNavigationItemSelectedListener()方法中使用它来处理点击事件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值