我們對Android開發非常陌生,所以如果這很明顯,我們很抱歉。Android 4.2上的TabHost - 圖標和顏色不顯示在選項卡上
我們正在使用選項卡式視圖實現一項活動。我們遇到的問題是標籤上的圖標和合適的顏色本身在Jelly Bean(Android 4.2)上沒有正確顯示。但是,它們可以在較早的API級別上正確顯示,例如薑餅。
請注意:我們最初使用棄用的TabActivity類創建視圖。但是,據我所知,這樣做的「新」方式不應該和舊的方式不同?如果我錯了,請糾正我。
這是一個包含標籤主機佈局XML:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/Black">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<include layout="@layout/logo_bar"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</FrameLayout>
</LinearLayout>
</TabHost>
下面是相關(我希望)活動代碼:
public class MainTabActivity extends FragmentActivity implements TabHost.TabContentFactory
private TabHost tabHost;
// other instance variables ...
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
tabHost = (TabHost)findViewById(android.R.id.tabhost);
tabHost.setup();
TabSpec loginTabSpec = tabHost.newTabSpec(GlobalConstants.LOGIN_ACTIVITY);
loginTabSpec.setIndicator("Settings", getResources().getDrawable(R.drawable.ic_action_settings_gear));
loginTabSpec.setContent(this);
TabSpec mainTabSpec = tabHost.newTabSpec(GlobalConstants.MAIN_ACTIVITY);
mainTabSpec.setIndicator("Lone Worker", getResources().getDrawable(R.drawable.ic_action_settings_phone));
mainTabSpec.setContent(this);
tabHost.addTab(mainTabSpec);
tabHost.addTab(loginTabSpec);
}
這就是標籤本身看起來像果凍豆(壞版本):
最後,這就是它應該看起來像什麼(在薑餅...良好的版本):
所以重新迭代:該選項卡的背景顏色是黑色的(當它通常是漂亮的藍色),並且儘管很難從錯誤的屏幕截圖中看出來,但是任一選項卡的圖標都缺失顯示在果凍豆上。我希望這個問題在這裏足夠概括。如果我遺漏了任何東西,請告訴我。先謝謝你!
u能PLZ告訴我或者指導我...怎麼給4.2中的選項卡之間的邊界標籤上的4.1邊界工作正常,當我在4.2中運行相同的項目時,選項卡之間的邊距消失,並且所有選項卡佔據相同的空間.... plz指導我如果你有一些解決方案。 ..謝謝 –
@NipunGogia我不知道,我從來沒有試圖在選項卡之間添加邊距。你可能想發佈你自己的問題,因爲我的問題與此無關。 –
好的謝謝.......... –