android:textallcaps="false",android:textAllCaps=“false” not working for TabLayout design S...

问题

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

How can I remove all caps?

回答1:

UPDATE FOR DESIGN LIBRARY 23.2.0+

The original answer doesn't work with design library 23.2.0 or later. Thanks for @fahmad6 pointed out in comment, in case someone missed that comment, I'll put it here. You need to set both textAllCaps and android:textAllCaps to false to disable all capitalize setting.

false

false

ORIGINAL ANSWER

By default, tabs are created by TabLayout sets the textAllCaps property to be true, you have to define a style making this flag false.

@style/MyCustomTextAppearance

false

回答2:

@Paresh Mayani answer is correct however you can create only tab style

false

And use it using

app:tabTextAppearance="@style/MyCustomTextAppearance"

.../>

回答3:

https://stackoverflow.com/a/34678235/1025379

app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"

/>

回答4:

use this attribute app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"

It will work.

android:id="@+id/tablayout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="center"

app:tabGravity="fill"

app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"

app:tabIndicatorColor="@color/colorPrimary"

app:tabMode="fixed"

app:tabPaddingStart="0dp" />

回答5:

For those who can't get working other answers.

Defining a style is working fine when you have single line tab text.

If you take a close look into the TabLayout, you'll see that it's using a field design_tab_text_size_2line when the tabs has more than one line.

The only way I could find to effect this field is to override it in your dimen file.

So put this in your values/dimens.xml

10sp

Hope it helps.

回答6:

In my case two variants work:

1) By Bogdan (susemi99):

app:tabTextAppearance="@android:style/TextAppearance.Widget.TabWidget"

/>

2) By Paresh Mayani. I wanted to have android:textAllCaps="false" and android:textSize="15sp" simultaneously, so his old method works.

In styles.xml write (parent may vary, for instance, "@android:style/TextAppearance.Widget.TabWidget", "TextAppearance.Design.Tab"):

@color/color_blue

@color/color_blue

@color/black

@style/TabLayoutTextAppearance

15sp

false

false

Apply this style in layout:

android:id="@+id/tab_layout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

style="@style/TabLayout"

/>

回答7:

Here is simple solution....Enjoy

for (int tabIndex = 0; tabIndex

TextView tabTextView = (TextView)(((LinearLayout)((LinearLayout)tabLayout.getChildAt(0)).getChildAt(tabIndex)).getChildAt(1));

tabTextView.setAllCaps(false);

}

回答8:

In versions priror to 14, you need to set (as commented by Paresh Mayani):

@style/MyCustomTextAppearance

false

But, in case of android version is equal or greater than 14, you need to set:

false

So, if you need to be compatible with versions before and after 14, you also need to create a folder values-v14, and a file styles.xml in that folder with the content:

false

回答9:

Try following method and you can implement all the methods of TextView in TabLayout

private void setCustomTab() {

ViewGroup vg = (ViewGroup) mTabLayout.getChildAt(0);

int tabsCount = vg.getChildCount();

for (int j = 0; j < tabsCount; j++) {

ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);

int tabChildsCount = vgTab.getChildCount();

for (int i = 0; i < tabChildsCount; i++) {

View tabViewChild = vgTab.getChildAt(i);

if (tabViewChild instanceof TextView) {

((TextView) tabViewChild).setTypeface(ResourcesCompat.getFont(this,R.font.montserrat_medium));

((TextView) tabViewChild).setAllCaps(false);

}

}

}

}

Hope it helps.

回答10:

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).

回答11:

Change: false

With: false

来源:https://stackoverflow.com/questions/31295116/androidtextallcaps-false-not-working-for-tablayout-design-support

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值