Я создал actionBar из actionBar Style Generator и скопировал стиль в своих приложениях. Создал пользовательский интерфейс для укладки вкладок с помощью tabwidget. , но когда я использую этот стиль в стиле манифеста в файле манифеста вроде android: theme = "@ style/Theme.Customtheme", который выглядит и чувствует себя не так, как панель действий (на версии 4.2), что я был создан в Action Bar Style Generator. Во-вторых, когда я запускаю свое приложение на Android 2.3.3, он показывает отличный внешний вид для Android 4.2. Я хочу, чтобы все выглядело на всех версиях, и я использую библиотеку sherlock для поддержки всей версии. Я много смотрел, но не получал идеального решения. Пусть кто-нибудь предложит ответ. благодарит заранее.Внешний вид и расположение уложенных вкладок отличается от версии <3.0 и отличается от версии> 3.0
Ниже мой код 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
Ваша минимальная версия sdk и целевая версия sdk одинаковы? – stinepike
нет, это андроид: minSdkVersion = "4" и android: targetSdkVersion = "17" –
делают то же самое, что и min sdk version и проверяют – stinepike