我已经设定android:textAllCaps="false"了android.support.design.widget.TabLayout它只显示全部大写的标题标题.
如何删除所有大写字母?
我正在使用android.support.widget.TabLayoutTab视图,我想从代码(而不是从xml或通过样式)更改选定的选项卡文本颜色.我怎样才能做到这一点 ?
这看起来应该很简单,但我无法想出办法.我需要一个选项卡来开始文本,但是在用户从列表中选择一个项目后,该文本会发生变化.我知道如何通过改变标签背景和颜色
mTabHost.getChildAt(index).setBackgroundColor();
Run Code Online (Sandbox Code Playgroud)
但是没有选项可以更改选项卡的指示器.我尝试过使用EditText.
private EditText tabName;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.statistics);
comm = new Communicator();
tabName = new EditText(this);
tabName.setText("BeginningText");
mTabHost = getTabHost();
mTabHost.addTab(mTabHost
.newTabSpec("tab_1_stat")
.setIndicator(User)
.setContent(R.id.meStatsTab));
mTabHost.addTab(mTabHost
.newTabSpec("tab_2_stat")
.setIndicator(tabName.getText())
.setContent(R.id.themStatsTab));
mTabHost.addTab(mTabHost
.newTabSpec("tab_3_stat")
.setIndicator("Archive")
.setContent(R.id.archiveStatsTab));
mTabHost.setOnTabChangedListener(this);
getTabWidget().getChildAt(1).setOnClickListener(new onThemTabClicked());
mTabHost.setCurrentTab(0);
onTabChanged("tab_1_stat");
Run Code Online (Sandbox Code Playgroud)
}
.....
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
tabName.setText("ChangedTabText");
Bundle extras = intent.getExtras();
themStats = extras.getStringArray("themStats");
mTabHost.setCurrentTab(1);
onTabChanged("tab_2_stat");
}
Run Code Online (Sandbox Code Playgroud)
这也不起作用,还有其他一些尝试.有任何想法吗?提前谢谢!
可能重复:
Android:以编程方式更改选项卡文本颜色
我们如何在android选项卡中更改文本颜色.
我的屏幕上有7个日期标签,选中标签后,文字为黑色; 而其他可选标签的颜色为白色.如果日期是另一个月,我希望文本颜色为灰色.
我假设第一个选项卡是0,第二个选项卡是1,并一直持续到6.如图所示,我想更改选项卡(3),选项卡(4),选项卡(5)和选项卡(6)的文本颜色.当它满足所需条件(而不是xml)时,如何以编程方式完成,将这4个选项卡中的文本颜色设置为灰色?
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin">
<TextView
android:id="@+id/lblWeekMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/week"
android:textAppearance="?attr/textAppearanceListItem" />
<TextView
android:id="@+id/lblWeekNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/lblWeekMsg"
android:layout_alignBaseline="@id/lblWeekMsg"
android:text=""
android:textAppearance="?attr/textAppearanceListItem" />
</RelativeLayout>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="30">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/app_bar_layout">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabTextColor="@android:color/white"
app:tabMode="scrollable"
app:tabGravity="fill" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我用这种方式用片段创建标签
public void setupViewPager(ViewPager viewPager, ArrayList<String> id, ArrayList<String> tasks,
ArrayList<Double> mondayHours, ArrayList<Double> tuesdayHours,
ArrayList<Double> wednesdayHours, ArrayList<Double> thursdayHours,
ArrayList<Double> fridayHours, ArrayList<Double> saturdayHours,
ArrayList<Double> sundayHours) {
Bundle …Run Code Online (Sandbox Code Playgroud)