- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有一个TabHost
:
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/onglets"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include
android:id="@+id/contentOnglet1"
layout="@layout/parcelle"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<include
android:id="@+id/contentOnglet2"
layout="@layout/liste_modele"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
</TabHost>
Java 代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle data = getIntent().getExtras();
if (!data.isEmpty()) {
label1 = data.getString(getResources().getString(R.string.extra_label_onglet1));
label2 = data.getString(getResources().getString(R.string.extra_label_onglet2));
data.clear();
}
setContentView(R.layout.tabHostLayout);
mTabHost = (TabHost)findViewById(R.id.onglets);
mTabHost.setup();
afficherOnglet1();
afficherOnglet2();
mTabHost.setCurrentTab(0);
}
private void afficherOnglet1() {
TabHost.TabSpec onglet1 = mTabHost.newTabSpec("onglet1");
View onglet = getLayoutInflater().inflate(R.layout.template_tab_onglets, null);
TextView label = (TextView) onglet.findViewById(R.id.tabLabel);
label.setText(label1);
onglet1.setIndicator(onglet);
View titre = (View)findViewById(R.id.title_tv_layout);
titre.setVisibility(View.GONE);
onglet1.setContent(R.id.contentOnglet1);
mTabHost.addTab(onglet1);
}
private void afficherOnglet2() {
TabHost.TabSpec onglet2 = mTabHost.newTabSpec("onglet2");
View onglet = getLayoutInflater().inflate(R.layout.template_tab_onglets, null);
TextView label = (TextView) onglet.findViewById(R.id.tabLabel);
label.setText(label2);
onglet2.setIndicator(onglet);
onglet2.setContent(R.id.contentOnglet2);
mTabHost.addTab(onglet2);
}
template_tab_onglets.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:id="@+id/tabLabel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:paddingTop="@dimen/paddingTitre"
android:paddingBottom="@dimen/paddingTitre"
android:background="@drawable/contour_tab_onglet"
android:textColor="@color/txt_color"
/>
</LinearLayout>
在 TabHost
的 onTabChangedListener
中,我想将 style
应用于 TextView
tabLabel ,一个粗体风格例如。怎么做?
最佳答案
方法是这样的
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabName) {
Log.i("***Selected Tab", "Im currently in tab with index::" + tabHost.getCurrentTab());
View v=tabHost.getCurrentTabView();
TextView title2 = (TextView) v.findViewById(R.id.tabLabel);
title2.setTypeface(Typeface.DEFAULT_BOLD);
}
});
关于android - 如何在 onTabChanged 中将样式应用于 TabHost 的选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29600046/
感谢您查看我的询问! 我已经实现了一个选项卡环境,如下图所示。它似乎按我的预期工作,只是它从不执行 onTabChanged 方法。我发现了一些关于这种情况的帖子,但无法让我的代码按我预期的方式工作。
我想更改 Android 选项卡小部件的背景。所以我用了这段代码 public static void setTabColor(TabHost tabhost) { for (int i =
在我的项目中,我有两个选项卡和一个按钮。对于两个选项卡,我有两个 Activity 和调用不同 Activity 的按钮。问题是我在第一个选项卡上显示按钮的结果。即 tab0 在 tab0Event
有一个TabHost: Java 代码: @Override
我有一个带有两个选项卡的选项卡主机。每个选项卡都有自己的 Activity 。我的目标是如果选项卡发生更改,则在其中一个选项卡中执行一种方法。我已经设置了这个 OnTabChangedListener
我正在开发 MVVM Android 应用程序。该 fragment 包含一个如下所示的 TabLayout: 我希望能够在 xml 中添加这一行: android:onTabChanged="
我是一名优秀的程序员,十分优秀!