我已经从 actionBar 样式生成器创建了 actionBar 并将样式复制粘贴到我的应用程序中。我使用 tabwidget 创建了堆叠选项卡的 UI。但是当我在我的清单文件中使用这种动作栏样式时,比如 android:theme="@style/Theme.Customtheme",它的外观和感觉与动作栏不同(在 4.2 版上),我是在动作栏样式生成器上创建的。其次是当我在 Android 2.3.3 上运行我的应用程序时,它会显示出与 android 4.2 不同的外观。我希望所有版本都具有相同的外观和感觉,并且我正在使用 sherlock 库来支持所有版本。我看了很多,但没有得到完美的解决方案。请任何人提出答案。提前致谢。
以下是我的代码 Sherlockfragment
public class CustomActivity extends SherlockFragmentActivity {
TabHost tHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom);
tHost = (TabHost) findViewById(android.R.id.tabhost);
tHost.setup();
/** Defining Tab Change Listener event. This is invoked when tab is changed */
TabHost.OnTabChangeListener tabChangeListener = new TabHost.OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
FragmentManager fm = getSupportFragmentManager();
ResidentialFragment resdentialFragment = (ResidentialFragment) fm.findFragmentByTag("residential");
CommercialFragment commercialFragment = (CommercialFragment) fm.findFragmentByTag("commercial");
FragmentTransaction ft = fm.beginTransaction();
if (resdentialFragment!=null) {
ft.detach(resdentialFragment);
}
/** Detaches the commercialfragment if exists */
if (commercialFragment!=null) {
ft.detach(commercialFragment);
}
/** If current tab is residential */
if(tabId.equalsIgnoreCase("residential")){
if(resdentialFragment==null){
/** Create residentialFragment and adding to fragmenttransaction */
ft.add(R.id.realtabcontent,new ResidentialFragment(), "residential");
}else{
/** Bring to the front, if already exists in the fragmenttransaction */
ft.attach(resdentialFragment);
}
}else{ /** If current tab is apple */
if(commercialFragment==null){
/** Create AppleFragment and adding to fragmenttransaction */
ft.add(R.id.realtabcontent,new CommercialFragment(), "commercial");
}else{
/** Bring to the front, if already exists in the fragmenttransaction */
ft.attach(commercialFragment);
}
}
ft.commit();
}
};
/** Setting tabchangelistener for the tab */
tHost.setOnTabChangedListener(tabChangeListener);
/** Defining tab builder for residential tab */
TabHost.TabSpec tSpecResidential = tHost.newTabSpec("residential");
tSpecResidential.setIndicator("Residential");
tSpecResidential.setContent(new DummyTabContent(getBaseContext()));
tHost.addTab(tSpecResidential);
/** Defining tab builder for commercial tab */
TabHost.TabSpec tSpecComm = tHost.newTabSpec("commercial");
tSpecComm.setIndicator("Commercial");
tSpecComm.setContent(new DummyTabContent(getBaseContext()));
tHost.addTab(tSpecComm);
}
}
以下是我的清单文件
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.customactivity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher">
<activity
android:name="com.example.customactivity.CustomActivity"
android:label="@string/projects"
android:theme="@style/Theme.Customtheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.customactivity.ResidentialFragment"
android:label="@string/title_activity_residential" >
</activity>
<activity
android:name="com.example.customactivity.CommercialFragment"
android:label="@string/title_activity_commercial" >
</activity>
</application>
</manifest>
在这里,我附上了我想要的外观。
以下来自 4.2 版的图片
以下来自版本 2.3.3 的图像