2012-10-30 16 views
10

रिश्तेदार लेआउट का उपयोग करते समय एक्शनबार शीर्षक नहीं दिखाता है। और जब मैं रिलेवेटिवआउट का उपयोग नहीं करता, तो आइटम सही से गठबंधन नहीं होते हैं। कृपया मुझे मेनू आइटम को समाधान के रूप में उपयोग करने के लिए न कहें। यह कस्टम होना चाहिए।कस्टम रिलेवेटिव के साथ एक्शनबैरशॉक शीर्षक शीर्षक नहीं दिखाता

यहाँ कैसे मैं इसे सेट है:

ActionBar bar = getSupportActionBar(); 
    bar.setDisplayOptions(
      ActionBar.DISPLAY_HOME_AS_UP | 
      ActionBar.DISPLAY_SHOW_CUSTOM | 
      ActionBar.DISPLAY_SHOW_HOME | 
      ActionBar.DISPLAY_SHOW_TITLE | 
      ActionBar.DISPLAY_USE_LOGO); 

    bar.setTitle(title); 
    bar.setCustomView(actionBar); 
    this.setTitle(title); 

यह जब संरेखित अच्छा है, लेकिन शीर्षक

<?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"> 

    <LinearLayout 
     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> 

Screenshot

नहीं दिखाया गया है और यहाँ लेआउट आता है जहां शीर्षक दिखाया गया है, लेकिन आइटम

<?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" 
    android:layout_gravity="right" 
    android:gravity="right"> 

    <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> 
पर बाएं हैं

Screenshot

उत्तर

12

मैं एक ही समस्या थी और इस लिंक मिल गया: https://groups.google.com/forum/?fromgroups=#!topic/actionbarsherlock/He6gst4nvR0

यह मेरे लिए काम किया:

लेआउट:

<?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> 

कोड:

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

लेआउट के लिए titleTextStyle साथ TextView जोड़कर एक समाधान नहीं है। यदि आपके किसी भी बेहतर जवाब है तो मैं इसे देखने के लिए उत्सुक हूं।

मेरे वैकल्पिक हल:

<?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

मैंने वही काम किया है। दुर्भाग्य से यह आरटीएल उपकरणों में ठीक से काम नहीं करता है। – AsafK

संबंधित मुद्दे