ActionBarSherlock with custom RelativeLayout does not show title text

后端 未结 2 1653
无人共我
无人共我 2020-12-14 11:39

The ActionBar does not show title when using relative layout. And when I not use the RelativeLayout, the items are not aligned to right. Please don\'t tell me to use menu it

相关标签:
2条回答
  • 2020-12-14 12:21

    I had the same problem and found this link: https://groups.google.com/forum/?fromgroups=#!topic/actionbarsherlock/He6gst4nvR0

    This worked for me:

    layout:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    
        ...
    
    </LinearLayout>
    

    code:

    import com.actionbarsherlock.app.ActionBar.LayoutParams;
    ...
    LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
    getSupportActionBar().setCustomView(segmentView, lp);
    
    0 讨论(0)
  • 2020-12-14 12:21

    There is a workaround by adding TextView with titleTextStyle to the layout. If any of you have a better answer i'm looking forward to see it.

    My workaround:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    
        <TextView
            android:id="@+id/player_title"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/buttons_holder"
            android:ellipsize="end"
            style="@style/TextAppearance.Sherlock.Widget.ActionBar.Title"/>
    
        <LinearLayout
            android:id="@+id/buttons_holder"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_alignParentRight="true" >
    
            <ImageButton
                android:id="@+id/acion_add"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/menu_label_add"
                style="?attr/actionButtonStyle" />
    
            <ImageButton
                android:id="@+id/action_prev"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/menu_label_prev"
                style="?attr/actionButtonStyle" />
    
            <ImageButton
                android:id="@+id/action_next"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/menu_label_next"
                style="?attr/actionButtonStyle" />
    
        </LinearLayout>
    
    </RelativeLayout>
    
    0 讨论(0)
提交回复
热议问题