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>
問題是:如何更改指示器顏色?
我知道我可以改變由AlertDialog使用的佈局,如:
builder = new AlertDialog.Builder(MainActivity.this, android.R.style.Theme_Dialog);
但我想要的佈局展現在畫面相同,但不同顏色的標籤指標。我可以從Android獲得這個,而不必重新定義整個指標嗎?