【问题标题】:How can i change the color of wave effect when I click on a tab of tablayout?单击tablayout的选项卡时如何更改波浪效果的颜色?
【发布时间】:2019-05-25 16:32:48
【问题描述】:

我正在使用tablayout,当我单击tablayout 的选项卡时,我不知道如何更改波浪效果的颜色。我怎样才能做到这一点 ? 谢谢你!!

Android Studio 的默认波浪效果

【问题讨论】:

  • 尝试更改您的 . primaryColor 或 colorAccent。
  • 点击时需要改变波浪效果的颜色,而不是tabbackground
  • 我编辑了我的新代码

标签: android android-layout android-tablayout


【解决方案1】:

试试这个:

tab_color_selector.xml 可绘制将ripple.xml 添加到state_pressed

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/blue_selected_tab" 
    android:state_selected="true"/>
    <item android:drawable="@drawable/ripple" android:state_pressed="true"/>
   <item android:drawable="@color/colorPrimary"/>
</selector>

ripple.xml 可绘制

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:color="@color/blue_selected_tab"
    tools:targetApi="lollipop"> <!-- ripple effect color -->
       <item android:id="@android:id/background">
       <shape android:shape="rectangle">
       <solid android:color="@color/blue_selected" /> <!-- background color -->
   </shape>
</item>

【讨论】:

  • 不,你的答案是改变tabbackground的颜色而不是波浪效果
  • tab_selector.xml 应该放在哪里?
  • tab_selector.xml 放入drawble 目录
  • 并设置为app:tabBackground="@drawable/tab_color_selector"
【解决方案2】:

enter image description here#ripple_bg.xml#

    <?xml version="1.0" encoding="utf-8"?>
    <ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@color/colorAccent" />

设置为tabbackground!

【讨论】:

  • 你的答案是改变tabbackground的颜色而不是波浪效果
  • 问题是如何改变波浪效果的颜色!我的回答有效。你只需要改变涟漪效果的颜色。我已经实现了这个
  • 查看附件图片
  • &lt;android.support.design.widget.TabLayout android:id="@+id/tablayout_id" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabBackground="@drawable/ripple_bg" android:background="@color/colorPrimary" app:tabMode="fixed" app:tabGravity="fill" &gt;&lt;/android.support.design.widget.TabLayout&gt; 不知道为什么不行
猜你喜欢
  • 1970-01-01
  • 2016-04-06
  • 1970-01-01
  • 2018-08-04
  • 1970-01-01
  • 2016-06-04
  • 2016-07-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多