Android button image is stretched using themes for ActionBar or ActionBarSherlock

I just integrated ActionBar into my Android app (in fact, I ended up going with ActionBarSherlock for its backward compatibility).

To display an ActionBar in action, you must use a specific set of themes: Theme.Holo. * for ActionBar or Theme.Sherlock. * for ActionBarSherlock

Whenever I modify AndroidManifest.xml so that the style of an existing action uses one of the above ActionBar themes, I find that the background image of each button in the activity is distorted. In particular, the image is stretched vertically by a larger number of pixels than the actual image contains. I would expect this behavior only if I used layout_height = "fill_parent", but I'm not sure. Moreover, it is not like other topics (except those related to ActionBar).

I tried to post screenshots, but so far I do not have a high enough reputation. I apologize.

Here is one of my Button ads affected by Theme:

<Button android:textStyle="bold" android:typeface="sans" android:layout_height="wrap_content" android:id="@+id/btnAddtoBag" android:layout_width="wrap_content" android:background="@drawable/add_to_bag_selector"> </Button> 

Since this refers to a selector, I will also include a selector XML where the actual png files are listed:

 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/selected_add_to_bag" /> <!-- pressed --> <item android:state_focused="true" android:drawable="@drawable/selected_add_to_bag" /> <!-- focussed --> <item android:drawable="@drawable/default_add_to_bag" /> <!-- default --> </selector> 

Finally, here is the style that I apply to my theme when this happens:

 <style name="Theme.CustomActionBar" parent="Theme.Sherlock.Light.DarkActionBar.ForceOverflow"> <item name="actionBarStyle">@style/ActionBar</item> </style> <style name="ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse"> <item name="android:displayOptions">showHome|useLogo</item> <item name="displayOptions">showHome|useLogo</item> </style> 
+4
source share
1 answer

use ImageButton and set android: src = "@ drawable / add_to_bag_selector" and your image should not be stretched.

you will also need to install android: backgorund = "@ android / color / transparent"

+7
source

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


All Articles