0
this answerを使用して、AlertDialog内でTabHostを取得できました。AlertDialog内のTabHost
ダイアログを表示するために使用されるコードは以下の通りである:
問題は、以下の図に示すようにタブインジケータは、背景と同じ色を有することである
AlertDialog.Builder builder;
AlertDialog alertDialog;
LayoutInflater inflater = (LayoutInflater)
getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.tabbed_dialog,
(ViewGroup) findViewById(R.id.tabhost));
TabHost tabs = (TabHost) layout.findViewById(R.id.tabhost);
tabs.setup();
TabHost.TabSpec tabpage1 = tabs.newTabSpec("foo");
tabpage1.setContent(R.id.ScrollView01);
tabpage1.setIndicator("foo");
TabHost.TabSpec tabpage2 = tabs.newTabSpec("bar");
tabpage2.setContent(R.id.ScrollView02);
tabpage2.setIndicator("bar");
tabs.addTab(tabpage1);
tabs.addTab(tabpage2);
builder = new AlertDialog.Builder(MainActivity.this);
builder
.setCancelable(false)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
builder.setTitle("Dialog with tabs");
builder.setView(layout);
alertDialog = builder.create();
alertDialog.show();
これが使用されているレイアウトです:
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="200px">
<TextView
android:id="@+id/TextView01"
android:text="foo text content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingLeft="15dip"
android:paddingTop="15dip"
android:paddingRight="20dip"
android:paddingBottom="15dip"
android:textColor="#000000"/>
</ScrollView>
<ScrollView android:id="@+id/ScrollView02"
android:layout_width="wrap_content"
android:layout_height="200px">
<TextView
android:id="@+id/TextView02"
android:text="bar text content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingLeft="15dip"
android:paddingTop="15dip"
android:paddingRight="20dip"
android:paddingBottom="15dip"
android:textColor="#000000"/>
</ScrollView>
</FrameLayout>
</LinearLayout>
</TabHost>
問題は:どのようにインジケータの色を変更するのですか?しかし、タブ指標の異なる色で、
builder = new AlertDialog.Builder(MainActivity.this, android.R.style.Theme_Dialog);
しかし、私は絵でshowと同じレイアウトをしたい:
私はのように、AlertDialogで使用されるレイアウトを変更することができます知っています。インジケータ全体を再定義せずにAndroidからこれを取得できますか?