Mark F
Mark F

Reputation: 1543

Add Slight Transparency To TabLayout Background

I have a Tablayout that looks like this:

enter image description here

I know that I can make the background of the TabLayout completely transparent with this line of code:

android:background="@android:color/transparent"

Is there a way to make it "slightly" more transparent instead? Is there something that I could add to my styles.xml file that could accomplish this? Here's what i'm using now:

 <style name="AppTabLayout" parent="Widget.Design.TabLayout">
    <item name="tabIndicatorColor">@android:color/white</item>
    <item name="tabIndicatorHeight">4dp</item>
    <item name="android:background">@color/colorPrimary</item>
    <item name="tabPaddingStart">6dp</item>
    <item name="tabPaddingEnd">6dp</item>
    <item name="tabTextAppearance">@style/AppTabTextAppearance</item>
    <item name="tabSelectedTextColor">@android:color/white</item>
</style>

<!-- for text -->
<style name="AppTabTextAppearance" parent="TextAppearance.Design.Tab">
    <item name="android:textSize">18sp</item>
    <item name="android:textColor">@android:color/black</item>
</style>

Upvotes: 0

Views: 914

Answers (2)

Shahbaz Ansari
Shahbaz Ansari

Reputation: 187

android:background="#90000000"

Simply change the value of first two digits to change transparent level

e.g

1) 90% - 90 e.g android:background="#90000000"
2) 80% - 80 e.g android:background="#80000000"
2) 70% - 70 e.g android:background="#70000000"
.
.
.

10% - 10 e.g android:background="#10000000"

Upvotes: 0

Hamed Nabizadeh
Hamed Nabizadeh

Reputation: 527

You can use color with alpha

android:background="#FF000000"

100% — FF

95% — F2

90% — E6

85% — D9

80% — CC

75% — BF

70% — B3

65% — A6

60% — 99

55% — 8C

50% — 80

45% — 73

40% — 66

35% — 59

30% — 4D

25% — 40

20% — 33

15% — 26

10% — 1A

5% — 0D

0% — 00

Upvotes: 1

Related Questions