Meaning of 'android:' prefix within attribute value (e.g. "android:imageButtonStyle") -
i want style imagebuttons in theme. after searching quite time found solution problem. don't know why works does.
my main layout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello world!" /> <imagebutton android:id="@+id/imagebutton" android:layout_width="wrap_content" android:layout_height="wrap_content" app:srccompat="@mipmap/ic_launcher_foreground" /> </linearlayout> this original theme didn't work. styles textview ignores imagebutton. result shown in screenshot below.
<resources> <style name="apptheme" parent="theme.appcompat.light.darkactionbar"> <item name="android:imagebuttonstyle">@style/redbackground</item> <item name="android:textviewstyle">@style/redbackground</item> </style> <style name="redbackground"> <item name="android:background">#ff0000</item> </style> </resources> and here's theme works:
<resources> <style name="apptheme" parent="theme.appcompat.light.darkactionbar"> <item name="imagebuttonstyle">@style/redbackground</item> <item name="android:textviewstyle">@style/redbackground</item> </style> <style name="redbackground"> <item name="android:background">#ff0000</item> </style> </resources> the difference missing 'android:' prefix in front of 'imagebuttonstyle' attribute.
so questions are:
- what difference between imagebuttonstyle , android:imagebuttonstyle?
- why android:textviewstyle work not android:imagebuttonstyle? both defined plattforms 'attrs.xml'.
- why there no textviewstyle (without android prefix)? removing prefix yields error.
- where attributes defined have no prefix? apparently not in plattforms 'attrs.xml'.
- where can find proper documentation whole style stuff? of course halve read respective google docs (https://developer.android.com/guide/topics/ui/look-and-feel/themes.html). still have basic questions one.
interestingly, seems 'android:imagebuttonstyle' version has worked years ago: how apply style imagebuttons in android?. haven't tested myself, though.
and here's post proposed removing android prefix. including unanswered comments ask why works: buttonstyle not working 22.1.1
android tag use used attribute coming android sdk.
app tag used if using support library.app namespace custom parameters custom view.
this can if see root element there's line xmlns:app="http://schemas.android.com/apk/res-auto" assigns namespace
you may see other namespaces if using custom views (of own or form library).


Comments
Post a Comment