我已经阅读了很多关于这个问题的其他线索,但是还没能解决我的问题。在Android 5.x我的应用程序工作正常。但是当在Android 4.4 Kit Kat上进行测试时,我遇到了一个问题。
问题: - 我的工具栏/操作栏功能正常,但仍然可以使用活动名称文本和汉堡包菜单项。我在下面附上图片来证明问题。
https://developer.apple.com/library/ios/samplecode/ViewControllerPreviews/Introduction/Intro.html
我有一个主要活动,带有导航栏,导航栏上的每个项目都会加载一个新片段。我使用以下设置进行片段定义。
public class <ClassName> extends android.support.v4.app.Fragment {}
我附加了我的2个样式XML文件&amp;我的主要片段文件,但我不确定这是否是问题所在。我也尝试删除受影响屏幕上的布局中的所有内容,但这也没有帮助。这是我第一次尝试在旧版Android上修复布局问题,所以我有点迷失。
我是否需要创建新的工具栏对象?
值/ styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">@color/whiteSystem</item>
<item name="tabTextColor">@android:color/white</item>
<item name="tabSelectedTextColor">@android:color/white</item>
</style>
</resources>
V21 / styles.xml
<resources>
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">@color/whiteSystem</item>
<item name="tabTextColor">@android:color/white</item>
<item name="tabSelectedTextColor">@android:color/white</item>
</style>
</resources>
有问题的片段类
import android.app.Activity;
//import android.app.Fragment;
//import android.app.FragmentManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class ParentFragment extends Fragment {
TabLayout tabLayout;
ViewPager viewPager;
private View myFragmentView; //this will enable 'findviewbyid' to be accessed
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myFragmentView = inflater.inflate(R.layout.parentFragment, container, false);
viewPager = (ViewPager) myFragmentView.findViewById(R.id.viewPager);
viewPager.setAdapter(new CustomAdaptor(getChildFragmentManager(), getActivity()));
tabLayout = (TabLayout) myFragmentView.findViewById(R.id.tabLayout);
tabLayout.setupWithViewPager(viewPager);
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
});
return myFragmentView;
}
private class CustomAdaptor extends FragmentPagerAdapter {
private String fragments[] = {"1", "2", "3", "4"};
public CustomAdaptor(FragmentManager fragmentManager, Activity activity) {
super(fragmentManager);
}
@Override
public android.support.v4.app.Fragment getItem(int position) {
switch (position) {
case 0:
return new FragmentOne();
case 1:
return new FragmentTwo();
case 2:
return new FragmentThree();
case 3:
return new FragmentFour();
default:
return null;
}
}
@Override
public int getCount() {
return fragments.length;
}
@Override
public CharSequence getPageTitle(int position) {
return fragments[position];
}
}
}