2012-06-29 12 views

उत्तर

0

नहीं, लेकिन आप आइकन को एक अलग लोगो ग्राफिक (android:logo और फिर setDisplayUseLogoEnabled()) से प्रतिस्थापित कर सकते हैं। आप लोगो ग्राफिक के हिस्से के रूप में अपना दो-पंक्ति शीर्षक एम्बेड कर सकते हैं और फिर setDisplayShowTitleEnabled() के माध्यम से मूल शीर्षक स्ट्रिंग नहीं दिखा सकते हैं। AFAIK, उस संयोजन को काम करना चाहिए।

+0

संकेत के लिए धन्यवाद, लेकिन मैं [setCustomView] के साथ इसे हल (http://developer.android.com/reference/android/app/ActionBar.html#setCustomView (पूर्णांक)) – benkap

6

एक्शनबार पर डिफ़ॉल्ट टेक्स्ट व्यू लाइन रैपिंग का समर्थन नहीं करता है, और इसे लपेटने के लिए सेट करने के लिए कोई खुला तरीका नहीं है। तो, एक लचीला लेआउट बनाने के इस तरह: action_bar_title_layout.xml:

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

<TextView 
    android:id="@+id/action_bar_title" 
    android:layout_height="match_parent" 
    android:layout_width="wrap_content" 
    android:gravity="center_vertical" 
    android:ellipsize="end" 
    android:maxLines="2"/> 

</LinearLayout> 

फिर अपने ActionBar पर कस्टम लेआउट के रूप में सेट:

ActionBar actionBar = getActionBar(); 
actionBar.setDisplayShowCustomEnabled(true); 
actionBar.setCustomView(R.layout.action_bar_title_layout); 
((TextView) findViewById(R.id.action_bar_title)).setText(
    "This is a long text title that will wrap to multiple lines, when necessary."); 
+0

अच्छा समाधान। धन्यवाद। – PeteH

12

मैं एक बेहतर समाधान है कि अप करने के लिए पूरी तरह से काम करता है पाया एंड्रॉइड 4.2.2 जहां आइकन और शीर्षक एक क्लिक करने योग्य आइटम हैं।

int titleId = Resources.getSystem() 
     .getIdentifier("action_bar_title", "id", "android"); 
if (titleId == 0) { 
    titleId = com.actionbarsherlock.R.id.abs__action_bar_title; 
} 
TextView title = (TextView) findViewById(titleId); 
if (title != null) { 
    title.setSingleLine(false); 
    title.setMaxLines(2); 
    title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); 
} 
+0

यह समर्थन लाइब्रेरी के एक्शनबार का उपयोग करके 4.4 के माध्यम से भी काम करता है। लेकिन प्लेटफ़ॉर्म पर विफल रहता है <= 2.3 – NKijak

31

मैं काफी यकीन है कि अगर आप निम्नलिखित देख रहे थे नहीं हूँ, लेकिन:

int titleId = Resources.getSystem() 
     .getIdentifier("action_bar_title", "id", "android"); 
if (titleId > 0) { 
    TextView title = (TextView) findViewById(titleId); 
    title.setSingleLine(false); 
    title.setMaxLines(2); 
    title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); 
} 

आप ActionBarSherlock का उपयोग कर रहे हैं, तो इस कोड का उपयोग

actionBar.setSubtitle (स्ट्रिंग स्ट्रिंग) आपके मुख्य शीर्षक के नीचे छोटे फ़ॉन्ट के साथ एक दूसरी पंक्ति सेट करता है।

उदाहरण:

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_left_drawer_item_clicked); 
     String value = getIntent().getExtras().getString("drawerItemString"); 

     ActionBar actionBar = getActionBar(); 
     // Make sure we're running on Honeycomb or higher to use ActionBar APIs 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 
      // Show the Up button in the action bar. 
      actionBar.setDisplayHomeAsUpEnabled(true); 
     } 
     actionBar.setTitle(selectedBook.getTitle()); 
     actionBar.setSubtitle(selectedBook.getAuthorName()); 

} 
+0

यहां सूचीबद्ध सर्वोत्तम समाधान। जवाब के रूप में चिह्नित किया जाना चाहिए! – Johan

+0

इस समाधान के साथ समस्या यह है कि यदि लेखक नाम खाली है, तो शीर्षक अभी भी पहली पंक्ति पर दिखाई देगा, जबकि दूसरी पंक्ति खाली रहती है। वह देखो अच्छा नहीं है ... –

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