angcyo / DslTabLayout

:hearts: Android界最万能的TabLayout(不仅仅是TabLayout), 支持任意类型的item, 支持Drawable类型的指示器,智能开启滚动,支持横竖向布局等
https://github.com/angcyo/DslAdapter
MIT License
1.55k stars 145 forks source link

大佬,item同时有图片和文字的,内部是默认只修改第一个吗 #110

Closed fumayer closed 1 month ago

fumayer commented 1 month ago

WX20240814-202055@2x

<com.angcyo.tablayout.DslTabLayout 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:id="@+id/tab_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/white" android:minHeight="50dp" app:tab_deselect_color="@color/text" app:tab_indicator_color="@color/colorAccent" app:tab_indicator_drawable="@drawable/indicator_bottom_line" app:tab_indicator_height="3dp" app:tab_item_is_equ_width="true" app:tab_select_color="@color/colorAccent" tools:tab_default_index="1"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:orientation="vertical">

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:src="@drawable/shape_round_background_tran_selector_test" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="哈哈哈哈" />
</LinearLayout>

就是这种,我用了LinearLayout,图片用了selector, 显示效果就是选中后图片会切换,但是文字颜色不会变

angcyo commented 1 month ago

可以通过属性tab_text_view_idtab_icon_view_id指定对应控件的id, 库就能自动处理了:

<!--指定文本控件的id, 所有文本属性改变, 将会发生在这个控件上, 如果指定的控件不存在, 控件会降权至[ItemView]-->
<attr name="tab_text_view_id" format="reference" />
<!--指定图标控件的id, 同上-->
<attr name="tab_icon_view_id" format="reference" />
fumayer commented 1 month ago

可是我看xml中只能指定一个id,我怎么让四个都实现 那种效果呢, 是需要在代码中指定id吗?

angcyo commented 1 month ago

4个图片控件用同一个id, 4个文本控件用同一个id. 即可.

fumayer commented 1 month ago

我用的databinding,xml中没法共用一个id,我再想想其他办法吧,多谢啦

angcyo commented 1 month ago

我用的databinding,xml中没法共用一个id,我再想想其他办法吧,多谢啦

官方的弃子, 为何还要用?

fumayer commented 1 month ago

啊?已经不推荐了吗,我都不知道