android:textAllCaps=“false” not working for TabLayout design Support

后端 未结 13 1441
暗喜
暗喜 2020-11-30 01:27

I have set android:textAllCaps=\"false\" in my android.support.design.widget.TabLayout thought it is showing the Tab Title in All caps only.

<
13条回答
  •  星月不相逢
    2020-11-30 02:08

    You can also do this in your Java code. If you are using a SlidingTabLayout look at this sample:

    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);//see line 38 above change the value their in TAB_VIEW_TEXT_SIZE_SP.
            textView.setTypeface(Typeface.DEFAULT);//From DEFAULT_BOLD
            textView.setTextColor(Color.parseColor("#536DFE"));//Text color of the words in the tabs. Indigo A200
    
            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
                // If we're running on Honeycomb or newer, then we can use the Theme's
            // selectableItemBackground to ensure that the View has a pressed state
                TypedValue outValue = new TypedValue();
                getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
                textView.setBackgroundResource(outValue.resourceId);
            }
    
            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH){
                // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
                textView.setAllCaps(true);
            }
    
            int padding = (int)(TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
            textView.setPadding(padding, padding, padding, padding);
    
            return textView;
        }
    

    Notice that textView.setAllCaps() has true as the perimeter:

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH){
                // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
                textView.setAllCaps(true);
            }
    

    When I changed this to (false) it solved the problem for me:

    textView.setAllCaps(false);
    

    Also my string resource file that I use for the tabs looks like this:

    Title with capital and smaller case
    

    However if it had all caps like >TITLE WITH ALL CAPS< you would still of course get all caps in your tabs.

    I made no other changes.

    It is noteworthy that you can set textView.setAllCaps(false) too, but this made no difference in my case. I just commented out textView.setAllCaps(true).

提交回复
热议问题