18

में बाएं, ऊपर, दाएं या नीचे बाईं ओर टैबलाउट आइकन बदलना मैं एंड्रॉइड विकास के लिए काफी नया हूं। तो मेरे साथ सहन करो।com.android.support:design:23.1.0

मैं एक दिन में com.android.support:design:23.1.0 में उसी पंक्ति में आइकन और टेक्स्ट को संरेखित करने का प्रयास कर रहा हूं।

स्पष्ट रूप से com.android.support:design: 23.1.0 उन्होंने डिफ़ॉल्ट आइकन स्थिति को शीर्ष पर और नीचे पाठ को बदल दिया है।

com.android.support:design में

पहले: 23.0.1 डिफ़ॉल्ट

तो यहाँ एक आसान तरीका हालांकि इसे हल करने (है चिह्न के रूप में एक ही पंक्ति में छोड़ दिया और पाठ पर आइकन था यह कमियां हो सकता है, tbh idk):

change the version in your app's build.gradle. ex: 23.1.0 to 23.0.1 and build. 

और वहाँ इसे इस तरह आप भी बाएँ, दाएँ, ऊपर, नीचे माउस पर संरेखित कर सकते हैं) करने के लिए (एक बेहतर तरीका है:

  1. रेस में एक custom_tab.xml बनाने/लेआउट
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textAlignment="center"/> 

अपनी गतिविधि जावा में 2.

TextView newTab = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null); 
newTab.setText("tab1"); //tab label txt 
newTab.setCompoundDrawablesWithIntrinsicBounds(your_drawable_icon_here, 0, 0, 0); 
tabLayout.getTabAt(tab_index_here_).setCustomView(newTab); 

अब तक मैं माउस बनाने के लिए हासिल कर लिया है किसी भी पक्ष पर प्रकट इस तरह:

TabLayout icons

पुनश्च: setCompoundDrawablesWithIntrinsicBounds समारोह तर्क इस तरह 4 पक्ष प्रतीक हैं:

setCompoundDrawablesWithIntrinsicBounds(leftDrawable, topDrawable, rightDrawable, bottomDrawable) 
+1

इस एचटी पर जाएं टीपी: //www.androidhive.info/2015/09/android-material-design-working-with-tabs/ आपकी मदद कर सकता है –

उत्तर

5

आप इस अच्छा टिप के लिए ATU धन्यवाद!

मेरे मामले में, मुझे केंद्र टैबलेटआउट शीर्षक के लिए एक रैखिक लेआउट जोड़ना होगा। मैंने आइकन और टेक्स्ट के बीच मार्जिन प्राप्त करने के लिए कुछ स्पेस वर्ण भी जोड़े हैं।

custom_tab.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" 
    android:gravity="center"> 
    <TextView 
     android:id="@+id/tabContent" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:textAlignment="center" 
     android:textColor="@android:color/white" 
     android:gravity="center"/> 
</LinearLayout> 

प्रारंभ कोड:

LinearLayout tabLinearLayout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.custom_tab, null); 
TextView tabContent = (TextView) tabLinearLayout.findViewById(R.id.tabContent); 
tabContent.setText(" "+getApplicationContext().getResources().getString(tabTitles[i])); 
tabContent.setCompoundDrawablesWithIntrinsicBounds(tabIcons[i], 0, 0, 0); 
mTabLayout.getTabAt(i).setCustomView(tabContent); 
+1

मुझे मार्जिन विचार पसंद है! – Atu

+0

https://stackoverflow.com/questions/36160978/align-icons-in-tab-layout-to-the-left/46247521#46247521 देखें –

0

ही एक्सएमएल कोड का प्रयोग करें @juzamn द्वारा दिए गए और सिर्फ पूरे टैब के लिए लूप को यह थोड़ा समायोजन जोड़ने

for (int i = 0; i < tabLayout.getTabCount(); i++) { 
yourlinearlayout = (LinearLayout) LayoutInflater.from(getContext()).inflate(R.layout.title_text, null); 
tab_text = (TextView) yourlinearlayout.findViewById(R.id.tabContent); 
     tab_text.setText(" " + tab_titles[i]); 
tab_text.setCompoundDrawablesWithIntrinsicBounds(tabicons[i], 0, 0, 0); 
    tabLayout.getTabAt(i).setCustomView(tab_text);}