7

मैं इस लक्ष्य को हासिल करना चाहते हैं:एंड्रॉइड टूलबार ऊंचाई कैसे सेट करें?

मैं क्या सोचा था कि एक बड़ा ऊंचाई के साथ एक कस्टम टूलबार बनाने के लिए और tabhost और tabpager सामान्य रूप से साथ काम करने की थी। मैंने इसे कार्यान्वित किया है, लेकिन टूलबार सामान्य ऊंचाई दिखा रहा है, इसलिए यह शीर्ष भाग के रूप में नहीं दिखता है। क्या यह सही दृष्टिकोण है या क्या एक रैखिक/सापेक्ष लेआउट के नीचे एक टैबहोस्ट सेट करना संभव है? क्योंकि मुझे एक्शन बार के रूप में इसके साथ काम करने की आवश्यकता नहीं है।

प्रासंगिक कोड

toolbar.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/toolbarTitle" 
    android:orientation="vertical" 
    android:background="@color/black" 
    android:layout_width="match_parent" 
    android:fitsSystemWindows="true" 
    android:minHeight="?attr/actionBarSize" 
    android:theme="@style/AppTheme" 
    android:layout_height="wrap_content"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    <ImageView 
     android:id="@+id/img_logo" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="55dp" 
     android:scaleType="centerInside" 
     android:src="@drawable/logo_home" 
     /> 

    <TextView 
     android:id="@+id/txt_version" 
     android:text="@string/app_version" 
     android:textColor="@color/white" 
     android:layout_below="@+id/img_logo" 
     android:paddingBottom="10dp" 
     android:paddingTop="15dp" 
     android:gravity="center" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 
    </RelativeLayout> 
</android.support.v7.widget.Toolbar> 

और गतिविधि में इस समारोह:

private void setupActionBar() 
    { 
     ActionBar ab = getSupportActionBar(); 
     ab.setDisplayShowCustomEnabled(true); 
     ab.setDisplayShowTitleEnabled(false); 
     LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     View v = inflator.inflate(R.layout.toolbar_title, null); 
     ab.setCustomView(v); 
    } 
+0

आप 'ActionBar' का उपयोग कर रहे हैं। आपका 'टूलबार' कोड कहां है? आप यहां अपने एंड्रॉइड में 'एंड्रॉइड: minHeight = "? Attr/actionBarSize" ऊंचाई को सेट कर सकते हैं। ऊंचाई का उपयोग करें और minHeight नहीं। –

उत्तर

11
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/toolbarTitle" 
android:orientation="vertical" 
android:background="@color/black" 
android:layout_width="match_parent" 
android:fitsSystemWindows="true" 
android:minHeight="?attr/actionBarSize" //pay attention here 
android:theme="@style/AppTheme" 
android:layout_height="wrap_content"> //pay attention here 

अपने ToolBar जो है एक ViewGroup जिसका अर्थ यह एक निश्चित आकार केवल अगर बच्चों से की जाती है मिल जाएगा अपने बच्चों के आसपास उसकी ऊंचाई wraping है। आपकी न्यूनतम ऊंचाई 50 से 60dip है, यह आपके ToolBar कितनी कम होगी। इसलिए यदि आपके बच्चों ऊंचाई एक उचित बड़ी संख्या को जोड़ नहीं है यह अभी भी हो जाएगा <= 50

यह एक पसंदीदा ऊंचाई android:layout_height="200dp"

0

इस गतिविधि या के लिए कोई कार्रवाई नहीं की पट्टी के साथ कुछ विषय का प्रयोग करें संपूर्ण ऐप अगर आपको एक्शन बार की कार्यक्षमता की आवश्यकता नहीं है (जैसे Theme.Holo.NoActionBar)। आप अपनी शीर्ष बार का लेआउट सीधे गतिविधियों रूट लेआउट में जोड़ सकते हैं। यदि आप इसे अन्य गतिविधियों में उपयोग करेंगे तो लेआउट के लिए अलग-अलग एक्सएमएल फाइलें या यहां तक ​​कि अपनी खुद की एक्शनबार्विव क्लास बनाने पर विचार करें।

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