Can't set title preference icon via? Attr

I created preference-headers.xml. I want to set the header icon via ?attr , but it does not show the icon.

 <?xml version="1.0" encoding="utf-8"?> <preference-headers xmlns:android="http://schemas.android.com/apk/res/android" > <header android:fragment="com.armsoft.mtrade.activities.PreferencesActivity$PrefsAboutFragment" android:icon="?attr/menuIconAbout" android:title="@string/about" /> </preference-headers> 
+4
source share
2 answers

I solved the problem with a mixture of headers.xml and icon change.

 public void onBuildHeaders(List<Header> target) { this.loadHeadersFromResource(R.xml.pref_headers, target); // search for the current header by comparing the titelRes Ids for (Header header : target) { if (header.titleRes == R.string.pref_style_title) { int themeDependIcon = ... //load the needed icon header.iconRes = themeDependIcon ; break; } } } 
+6
source

I have the same problem with title icons for multiple topics.

The only way is to create headers in the code ...

 @Override public void onBuildHeaders(List<Header> target) { final TypedArray a = getTheme().obtainStyledAttributes(R.style.<YourTheme>, new int[] = { R.attr.icon1, R.attr.icon2}); final Header h1 = new Header(); h1.title = "title 1"; h1.iconRes = a.getResourceId(0, 0); h1.fragment = "<your_fragment_path>"; h1.fragmentArguments = new Bundle(); h1.fragmentArguments.putString("id", "fragment1"); final Header h2 = new Header(); h2.title = "title 2"; h2.iconRes = a.getResourceId(1, 0); h2.fragment = "<your_fragment_path>"; h2.fragmentArguments = new Bundle(); h2.fragmentArguments.putString("id", "fragment2"); target.add(h1); target.add(h2); a.recycle(); } 
+1
source

All Articles