我在玩弄新的 android.support.design.widget.TabLayout
,并发现了一个问题,在类的定义,有没有方法改变指示灯的颜色和默认的高度。
I was playing around with the new android.support.design.widget.TabLayout
, and found a problem, in the class definition, there are no methods to change the indicator color, and default height.
做一些研究,发现默认的指示灯颜色取自AppTheme。特别是从这里开始:
Doing some research, found that the default indicator color is taken from the AppTheme. Specifically from here:
<item name="colorAccent">#FF4081</item>
现在,在我的情况,如果我改变了 colorAccent
,就会影响到所有其他视图,它使用这个值作为背景色,例如进度
Now, in my case, if I change the colorAccent
, it will affect all the other views which uses this value as background color, for example ProgressBar
现在有没有什么办法的indicatorColor更改为另一件事除了 colorAccent
?
Now is there any way to change the indicatorColor to other thing besides the colorAccent
?
有了新TabLayout使用指示灯的颜色从值 colorAccent
的问题,我决定挖到 android.support.design.widget.TabLayout
执行,发现没有任何公开的方法来进行定义。但是我发现TabLayout的这种风格说明:
Having the problem that the new TabLayout uses the indicator color from the value colorAccent
, I decided to dig into the android.support.design.widget.TabLayout
implementation, finding that there are no public methods to customize this. However I found this style specification of the TabLayout:
<style name="Base.Widget.Design.TabLayout" parent="android:Widget">
<item name="tabMaxWidth">@dimen/tab_max_width</item>
<item name="tabIndicatorColor">?attr/colorAccent</item>
<item name="tabIndicatorHeight">2dp</item>
<item name="tabPaddingStart">12dp</item>
<item name="tabPaddingEnd">12dp</item>
<item name="tabBackground">?attr/selectableItemBackground</item>
<item name="tabTextAppearance">@style/TextAppearance.Design.Tab</item>
<item name="tabSelectedTextColor">?android:textColorPrimary</item>
</style>
有这种风格的规范,现在我们可以自定义TabLayout是这样的:
Having this style specification, now we can customize the TabLayout like this:
<android.support.design.widget.TabLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@id/pages_tabs"
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:tabIndicatorColor="@android:color/white"
app:tabIndicatorHeight="4dp"/>
和问题解决了,这两个选项卡指示灯的颜色,高度可以从改变其缺省值。
And problem solved, both the tab indicator color and height can be changed from their default values.
上一篇:Android的表格布局ROWSPAN布局、表格、Android、ROWSPAN
下一篇:我跟踪我对谷歌Analytics(分析)Android应用程序。为什么我似乎有Macintosh用户?我对、应用程序、用户、Android