android - 更改选定的 TabItem 高度
问题描述
我正在使用 TabLayout 并且我正在寻找一种方法来更改所选 TabItem 的高度,所以这个会比其他的要大。为此,我尝试使用 TabIndicator,但我只能更改它的颜色和大小,而不是它的位置(它总是在 TabLayout 内,我需要将它放在它的正上方以达到我需要的效果)。
有没有办法使用选择器或在布局 xml 本身中实现这一点?
下面是所需效果的示例(左侧是选定的选项卡):
这是我到目前为止的代码:
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorHeight="0dp"
app:tabBackground="@drawable/nav_item_color_state">
<android.support.design.widget.TabItem
android:id="@+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab 1"/>
<android.support.design.widget.TabItem
android:id="@+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tab 2"/>
</android.support.design.widget.TabLayout>
</android.support.constraint.ConstraintLayout>
解决方案
我最终使用了两个按钮并创建了两个不同的可绘制对象,以在其背景中用作选择/未选择状态。一点也不优雅,但它奏效了。
推荐阅读
- delphi - 如何知道节点是 Virtual TreeView 中的根节点?
- c++ - 如何将键和值从映射转移到另一个映射?
- kubernetes - 需要澄清 kuberentes 部署 yaml 如何用于创建角色
- haskell - Fay找不到fay-base
- excel - 使用 Excel MailEnvelope 在 Outlook 邮件中自动调整
- laravel - 将数据从 Laravel 传递和存储到 Vue 的正确方法
- android - 我怎样才能反序列化这个?
- php - 试图获取非对象的属性“名称”(查看:
- python - 如何将一个列表添加到另一个列表
- mongodb - 是否可以将mongodb设置为在满足特定条件时自动更新文档?