android - Changing the highlight and title color for fragments in PreferenceActivity -
android - Changing the highlight and title color for fragments in PreferenceActivity -
i'm using material theme, , i'd alter color of 2 marked areas in image below - i.e. highlight color (#1) , color of title in details fragment (#2).
i know there's attribute color of each somewhere in theme, can't seem find it.
any ideas?
i know there's attribute color of each somewhere in theme, can't seem find it.
item number 1the attribute you'll want activatedbackgroundindicator
.
as per docs
drawable used background activated items.
reason being
the layout used each header item in preferenceactivity
preference_header_item_material
uses activatedbackgroundindicator
background. you'll need selector attribute, like:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_activated="true"><color android:color="yourcolor" /> </item> <item><color android:color="@android:color/transparent" /> </item> </selector>
item number 2 this item trickier. it's not preferencescreen
suggested in other answer, fragmentbreadcrumbs
title. unfortunately, title color cannot set using theme because attribute used style private internal.
you can set text color using reflection or traversing breadcrumb's view hierarchy until find textview
used display title.
the layout used display content in each preferenceactivity
preference_list_content_material
includes breadcrumbs_in_fragment_material
layout display each breadcrumb. can see layout id of each fragmentbreadcrums
android:id/title
. can utilize id find breadcrumb , adjust the textview
within it.
using reflection
@override public void onbuildheaders(list<header> target) { super.onbuildheaders(target); loadheadersfromresource(r.xml.yourpreferenceheaders, target); final view breadcrumb = findviewbyid(android.r.id.title); if (breadcrumb == null) { // single pane layout return; } seek { final field titlecolor = breadcrumb.getclass().getdeclaredfield("mtextcolor"); titlecolor.setaccessible(true); titlecolor.setint(breadcrumb, yourtitlecolor); } grab (final exception ignored) { // nil } }
traversing view hierarchy
using view.findviewswithtext
easy way handle this.
breadcrumb.getviewtreeobserver().addongloballayoutlistener(new ongloballayoutlistener() { @override public void ongloballayout() { breadcrumb.getviewtreeobserver().removeongloballayoutlistener(this); final arraylist<view> outviews = lists.newarraylist(); breadcrumb.findviewswithtext(outviews, getstring(r.string.your_header_title), view.find_views_with_text); ((textview) outviews.get(0)).settextcolor(yourtitlecolor); } });
results android android-theme
Comments
Post a Comment