2015-02-04 8 views
6

हाय मैं अपने ऐप में स्लाइडिंग टैब लेआउट का उपयोग कर रहा हूं और यह सब बहुत अच्छा काम करता है। केवल एक चीज जिसे मैं समझ नहीं पा रहा हूं, मेरा टैब टेक्स्ट अपरकेस में क्यों है।स्लाइडिंग टैब लेआउट टेक्स्ट अपरकेस

मैंने टैब को स्लाइडिंग टैब क्लास के अंदर प्राप्त टेक्स्ट मुद्रित किया है और वे अपरकेस में नहीं हैं। मैंने चारों ओर देखा है और अपरकेस विधि को कॉल करने के लिए कोई नहीं है।

private void populateTabStrip() { 
     final PagerAdapter adapter = mViewPager.getAdapter(); 
     final View.OnClickListener tabClickListener = new TabClickListener(); 

     for (int i = 0; i < adapter.getCount(); i++) { 
      View tabView = null; 
      TextView tabTitleView = null; 

      if (mTabViewLayoutId != 0) { 
       // If there is a custom tab view layout id set, try and inflate it 
       tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, 
         false); 
       tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); 
      } 

      if (tabView == null) { 
       tabView = createDefaultTabView(getContext()); 
      } 

      if (tabTitleView == null && TextView.class.isInstance(tabView)) { 
       tabTitleView = (TextView) tabView; 
      } 

      if (mDistributeEvenly) { 
       LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); 
       lp.width = 0; 
       lp.weight = 1; 
      } 

      tabTitleView.setText(adapter.getPageTitle(i)); 
      tabTitleView.setTextColor(getResources().getColor(R.color.da_blue)); 
      tabView.setOnClickListener(tabClickListener); 
      String desc = mContentDescriptions.get(i, null); 
      if (desc != null) { 
       tabView.setContentDescription(desc); 
      } 

      mTabStrip.addView(tabView); 
      if (i == mViewPager.getCurrentItem()) { 
       tabView.setSelected(true); 
      } 
     } 
    } 

मुझे लगता है मैं एक शैली के माध्यम से यह कर सकते हैं सुनिश्चित करें, लेकिन वास्तव में नहीं पता कि कौन से एक का उपयोग करने के लिए नहीं कर रहा हूँ:

यहाँ वर्ग है कि पाठ सेट से कोड है। मेरे पास मेरी शैलियों में यही है:

<resources> 

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="android:actionBarTabTextStyle">@style/ActionBarTabTextStyle.Tabtheme</item> 
     <item name="actionBarTabTextStyle">@style/ActionBarTabTextStyle.Tabtheme</item> 
    </style> 


    <style name="ActionBarTabTextStyle.Tabtheme" parent="@android:style/Widget.Holo.ActionBar.TabText"> 
     <item name="android:textAllCaps">false</item> 
    </style> 
</resources> 
+0

आप एल में यह देख रहे हैं? यह डिफ़ॉल्ट व्यवहार है। यदि आप सभी कैप्स नहीं चाहते हैं तो आप इस जवाब का उल्लेख कर सकते हैं। http://stackoverflow.com/questions/26958909/why-is-my-button-text-coerced-to-all-caps-on-lollipop/26959656#26959656 –

उत्तर

5

उत्तर मिला कि यह createDefaultTabView() विधि में था।

textView.setAllCaps (सत्य) को गलत में बदलने की आवश्यकता है।

protected TextView createDefaultTabView(Context context) { 
    TextView textView = new TextView(context); 
    textView.setGravity(Gravity.CENTER); 
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); 
    textView.setLayoutParams(new LinearLayout.LayoutParams(
      ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 

    TypedValue outValue = new TypedValue(); 
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, 
      outValue, true); 
    textView.setBackgroundResource(outValue.resourceId); 
    textView.setAllCaps(false); **// Changed to false and it did the trick** 

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); 
    textView.setPadding(padding, padding, padding, padding); 

    return textView; 
} 
+0

उपर्युक्त विधि में TAB_VIEW_TEXT_SIZE_SP मान बदलने की कोशिश कर रहा है लेकिन परिवर्तन प्रतिबिंबित नहीं होते हैं –

16

आप "android.support.design.widget.TabLayout" स्थापित करने के लिए app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"

+0

केवल यह मेरे लिए काम किया –

+0

धन्यवाद। इससे मेरा काम बनता है! – susemi99

0

सिर्फ populateTabStrip में इस लाइन tabTitleView.setAllCaps(false); जोड़ने की जरूरत है()

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