2015-09-25 12 views
17

पर कस्टम लेआउट जोड़ें मैंने अपने ऐप को कुछ टैब के साथ एक नियमित टूलबार देने के लिए इस tutorial का पालन किया।टूलबार

मैं उपकरण पट्टी को बदलना चाहते हैं, तो यह अधिक इस तरह दिखता है:

enter image description here

मैं उपकरण पट्टी में कुछ पाठ और छवियों को जोड़ना चाहते हैं। मैं यह कैसे कर सकता हूँ?

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     app:elevation="0dp"> 

     <android.support.v7.widget.Toolbar 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:app="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="@color/primary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:theme="@style/ToolbarTheme" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
      /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabTextAppearance="@style/TabLayout" 
      app:tabSelectedTextColor="@color/white" 
      /> 

    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/pager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     /> 

</android.support.design.widget.CoordinatorLayout> 
+0

यह एक एकल लाइन टूलबार है, अन्य जानकारी एक ही पृष्ठभूमि रंग के साथ केवल रैखिक लेआउट है। इसके अलावा आप टूलबार के अंदर दृश्य जोड़ सकते हैं बस एक बंद टैग ' ' – NaviRamyle

+0

यदि मैं टूलबार टैग के भीतर लेआउट जोड़ता हूं, क्या व्यवहार बदलता है? यदि टूलबार 500 पिक्सेल लंबा है तो क्या होगा? – user5374735

+0

अप्रत्यक्ष डुप्लिकेट [एंड्रॉइड में नीचे टूलबार बनाने का सबसे अच्छा तरीका]] (http://stackoverflow.com/questions/30063426/best-way-to-create-a-bottom-toolbar-in-android) – Elltz

उत्तर

8

आप इस कोशिश कर सकते हैं: -

<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/main_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


     <!- Your view --> 


    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:elevation="6dp" 
     android:fitsSystemWindows="true" 
     android:theme="@style/AppTheme"> 


     <android.support.v7.widget.Toolbar 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:id="@+id/toolbar" 
     android:layout_height="?attr/actionBarSize" 
     android:elevation="6dp" 
     app:layout_collapseMode="pin" 
     app:layout_scrollFlags="scroll|enterAlways" 
     app:popupTheme="@style/AppTheme"> 

      <LinearLayout 
       android:id="@+id/llContainer" 
       android:layout_width="match_parent" 
       android:orientation="vertical" 
       android:background="@android:color/black" 
       android:gravity="center" 
       android:layout_height="300dp"> 

       <!- Your TextView/ImageView --> 

      </LinearLayout> 

     </android.support.v7.widget.Toolbar> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabTextAppearance="@style/TabLayout" 
      app:tabSelectedTextColor="@color/white"/> 

</android.support.design.widget.AppBarLayout> 

<android.support.v4.view.ViewPager 
    android:id="@+id/pager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    /> 

</android.support.design.widget.CoordinatorLayout> 
0

एंड्रॉयड ActionBar अब तथ्य यह है कि वर्ष ActionBar तत्व के साथ प्रतिस्थापित किया गया है की वजह से पहले से कहीं ज्यादा अनुकूलित करने के लिए, आसान है अधिक बहुमुखी टूलबार। अधिक detail reference link 1 और detail reference link 2

0

आप नीचे दिखाए गए बाधा लेआउट का उपयोग करके टूलबार कस्टम लेआउट को परिभाषित कर सकते हैं, अधिक जानकारी के लिए http://www.zoftino.com/android-toolbar-tutorial देखें।

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="zoftino.com.toolbar.MainActivity"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:minHeight="?attr/actionBarSize" 
     app:layout_constraintEnd_toEndOf="parent" 
     app:layout_constraintStart_toStartOf="parent" 
     app:layout_constraintTop_toTopOf="parent"> 
     <android.support.constraint.ConstraintLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginBottom="8dp"> 
      <TextView 
       android:id="@+id/title_m" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginEnd="8dp" 
       android:layout_marginStart="8dp" 
       android:layout_marginTop="16dp" 
       android:text="Tennis" 
       android:textAppearance="@android:style/TextAppearance.Material.Title" 
       app:layout_constraintLeft_toLeftOf="parent" 
       app:layout_constraintRight_toRightOf="parent" 
       app:layout_constraintTop_toTopOf="parent"/> 
      <TextView 
       android:id="@+id/women_s" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginEnd="8dp" 
       android:layout_marginStart="8dp" 
       android:layout_marginTop="8dp" 
       android:text="W Singles" 
       android:textAppearance="@android:style/TextAppearance.Material.Medium" 
       app:layout_constraintLeft_toLeftOf="parent" 
       app:layout_constraintRight_toRightOf="parent" 
       app:layout_constraintTop_toBottomOf="@+id/title_m" /> 
      <TextView 
       android:id="@+id/wm_name" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginEnd="8dp" 
       android:layout_marginStart="8dp" 
       android:layout_marginTop="8dp" 
       android:textAppearance="@android:style/TextAppearance.Material.Title" 
       android:text="Serena" 
       app:layout_constraintLeft_toRightOf="@+id/women_s" 
       app:layout_constraintRight_toRightOf="parent" 
       app:layout_constraintTop_toBottomOf="@+id/title_m" /> 

     </android.support.constraint.ConstraintLayout> 
    </android.support.v7.widget.Toolbar> 


</android.support.constraint.ConstraintLayout> 
संबंधित मुद्दे