Created a tab_icon_selector file to dynamicaly color the Pie chart icon in the HomeFragment tabs in the activated/deactivated state in both day and night mode to match the same colors as the other tab's text.

master
Severiano Jaramillo 2019-01-21 21:54:18 -06:00
parent e3f8e1d923
commit 6841e3eb9a
3 changed files with 25 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import android.preference.PreferenceManager
import android.view.*
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.DrawableCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
@ -18,6 +19,10 @@ import cy.agorise.bitsybitshareswallet.database.entities.UserAccount
import cy.agorise.bitsybitshareswallet.utils.Constants
import cy.agorise.bitsybitshareswallet.viewmodels.UserAccountViewModel
import kotlinx.android.synthetic.main.fragment_home.*
import android.os.Build
import android.content.res.ColorStateList
class HomeFragment : Fragment() {
@ -97,6 +102,18 @@ class HomeFragment : Fragment() {
tabLayout.setupWithViewPager(viewPager)
// Set the pie chart icon for the third tab
tabLayout.getTabAt(2)?.setIcon(R.drawable.ic_pie_chart)
var icon = tabLayout.getTabAt(2)?.icon
if (icon != null) {
val colors: ColorStateList = if (Build.VERSION.SDK_INT >= 23) {
resources.getColorStateList(R.color.tab_icon_selector, context?.theme)
} else {
resources.getColorStateList(R.color.tab_icon_selector)
}
icon = DrawableCompat.wrap(icon)
DrawableCompat.setTintList(icon, colors)
}
}
/**

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?android:textColorPrimary"
android:state_selected="true" />
<item android:color="?android:colorControlNormal" />
</selector>

View File

@ -158,6 +158,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@color/semiTransparent"
app:tabTextColor="?android:colorControlNormal"
app:tabSelectedTextColor="?android:textColorPrimary"
app:tabIndicatorColor="?attr/themedColorBackgroundFloating"
app:tabIndicatorHeight="50dp"