How to inherit an Android style attribute?

I recently tried applying a style based on my Android app. However, I am stuck in this dilemma.

In my layout file, I originally had this:

<LinearLayout android:id="@+id/layout_event_buttons" style="?android:attr/buttonBarStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal" > <ImageButton android:id="@+id/btn_create_event" style="?android:attr/buttonBarButtonStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/btn_save" android:src="@drawable/content_save" android:text="@string/btn_save" /> </LinearLayout> 

In my .xml styles, I tried doing this without any luck:

 <style name="Buttons" parent="?android:attr/buttonBarButtonStyle"> <item name="android:layout_width">match_parent</item> <item name="android:layout_height">wrap_content</item> </style> 

I have already tried the different options above, for example:

?android:buttonBarButtonStyle

?attr:buttonBarButtonStyle

@android:attr/buttonBarButtonStyle

@android:buttonBarButtonStyle

I also tried:

 <item name="style">?android:attr/buttonBarButtonStyle</item> 

to no avail.

My application will not compile because it cannot find the buttonBarButtonStyle resource.

Here is how I applied it. My other styles work just fine if I just inherit common themes like Holo etc.

 <ImageButton style="@style/Buttons" android:id="@+id/btn_create_event" android:contentDescription="@string/btn_save" android:src="@drawable/content_save" android:text="@string/btn_save" /> 
+6
source share
2 answers

Found an answer similar to this post: How does the android: attr style work?

It turns out that this style is private, and you may have to completely copy it so that you can turn it off. :(

+3
source

I found that applying android:background="?android:attr/selectableItemBackground" to the attributes of a button removes the borders, which makes the button act like an android button bar (after the extension ?android:attr/buttonBarButtonStyle , as you have.

This post explains it well.

0
source

Source: https://habr.com/ru/post/954631/


All Articles