Android ActionBar setActionView layout issue

后端 未结 2 1342
说谎
说谎 2021-01-18 18:42

I\'ve been trying to use the setActionView from the ActionBar in ICS

Seems like it should be straight forward but somehow I\'m not getting the layout alignment that

相关标签:
2条回答
  • 2021-01-18 19:03

    It seems that explicitly defining the style and adding a 4dip padding in the root of the layout to inflate as shown below solves this issue

    <ImageView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:paddingLeft="4dip"
        android:paddingRight="4dip"
        style="?android:attr/actionButtonStyle" />
    

    This seems to be used in the android stylesheet here

    0 讨论(0)
  • 2021-01-18 19:15

    A little late but the right solution is not an absolute value such as 4dp. The right approach is to set the minWidth to ABS values:

    android:minWidth="@dimen/abs__action_button_min_width"
    

    Example progress bar:

    <?xml version="1.0" encoding="utf-8"?>
    
    <ProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
                 android:minWidth="@dimen/abs__action_button_min_width"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:focusable="true"
                 android:layout_gravity="center"
                 style="@android:style/Widget.ProgressBar.Small"/>
    
    0 讨论(0)
提交回复
热议问题