5 つのタブを保持する TabHost があります。私が見る限り、常に 1 つのタブを選択する必要があります。
すべてのタブを選択解除して、何も選択されないようにする方法が必要です。
タブホストが一般的に常に1つのタブを選択することを意図している場合、タブが選択されていないかのように(UIで)表示するにはどうすればよいですか?
5 つのタブを保持する TabHost があります。私が見る限り、常に 1 つのタブを選択する必要があります。
すべてのタブを選択解除して、何も選択されないようにする方法が必要です。
タブホストが一般的に常に1つのタブを選択することを意図している場合、タブが選択されていないかのように(UIで)表示するにはどうすればよいですか?
これを試して:
final TabWidget tabWidget = tabHost.getTabWidget();
final int n = tabWidget.getChildCount();
for (int i = 0; i < n; ++i) {
tabWidget.getChildAt(i).setSelected(false);
}
または、非表示のタブを追加して、タブの選択を解除したいときに選択することができます
tabHost.addTab(
tabHost.newTabSpec("hiddenTab").setIndicator(""),
MyFragment.class,
null
);
tabHost.getTabWidget().getChildTabViewAt(hiddenTabIndex).setVisibility(View.GONE);
必要なときにこのタブを選択します
tabHost.setCurrentTab(hiddenTabIndex);
これはAFAIKでは不可能です。ただし、選択したタブの色を選択されていないように設定し、「選択解除」したときにグローバル変数を管理し、ユーザーに通常表示したいときに通常のレイアウトを設定することで、その上に空白のレイアウトを設定できます。 。しかし、これは一種のトリックです。
願っています、あなたは私のポイントを取得します!
編集 :
String what="disappear"
コードのどこかに「選択されていない」と表示するように設定したとすると、この関数を使用してタブの色を変更できます。
Main.class:
//Change The Backgournd Color of Tabs
public void setTabColor(TabHost tabhost) {
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
{
tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#FFFFFF"))); //unselected white colored
}
if(!what.equals("disappear"))
tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.parseColor("FF0000"))); // selected red colored
else
tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.parseColor("FFFFFF"))); // selected but show as unselected with white color
}
そしてあなたの活動クラス(その選択されたタブによって開かれる)で:
FirstActivity.class:
if(what.equals("disappear"))
setContentView(R.layout.blank);
else
setContentView(R.layout.first_layout);
blank.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/layout"
android:background="#ffffff"
android:gravity="center">
<!-- You can make background transperent by setting it to "00ffffff" -->
<!-- You can also add this textview to guide user -->
<!--
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click Any Tab To Start
/>
-->
</LinearLayout>
この目的のために、おそらく tabHost を使用するのは適切な方法ではありませんか?