【发布时间】:2017-03-13 17:24:47
【问题描述】:
如何通过 java 代码动态更改选项卡背景这是我的布局代码。如果我可以在 java 代码中获取 app:tabBackground="@drawable/tab_background" 那么我可以使用选择器通过选项卡选择的位置更改可绘制的背景,以获得所需的屏幕,如第一张图片,但我无法在任何地方找到它,请朋友们帮帮我
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.design.widget.TabLayout
android:id="@+id/icon_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/toolbar_bg"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
app:tabBackground="@drawable/tab_background"
app:tabIndicatorColor="@color/transparent"
app:tabGravity="fill"
app:tabMode="fixed" />
<FrameLayout
android:id="@+id/main_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
我需要像下面这样的布局
但是我得到了这个布局
【问题讨论】:
标签: java android android-layout android-tabs android-tablayout