【发布时间】:2015-07-10 16:43:26
【问题描述】:
我在我的应用的 First Activity 中使用带有一些操作栏按钮的 AppCompatActivity。
来自第二个活动,我正在使用滑动标签。
我的 theme.xml(主题 1)
<style name="CustomActionBarTheme" parent="Theme.AppCompat">
<!-- theme customizations -->
<item name="colorPrimary">@color/easy</item>
<item name="colorAccent">@color/easy</item>
<!-- Size Of Action bar-->
<item name="actionBarSize">55dp</item>
</style>
第一个活动工作正常。使用上述主题但是
我的滑动标签页出错
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.slidingtab}:
java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor.
Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
我的主题.xml(主题 2)
<style name="CustomActionBarTheme" parent="Theme.AppCompat">
</style>
<style name="MyTheme.NoActionBar">
<!-- Both of these are needed -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
如果我使用上述主题,Sliding TAB 页面工作正常,但我的第一个活动显示 NPE。
问题:
1.我想要第一个活动的自定义主题,
2.我也需要在第二个活动中滑动标签
如何解决这个问题,请帮助我。
编辑:1
添加了 Oncreate 方法
我的滑动标签 Oncreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.find_stores_0_tabview__landing);
// for ActionBar back button
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Initilization
// Creating The Toolbar and setting it as the Toolbar for the activity
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
// Creating The ViewPagerAdapter and Passing Fragment Manager, Titles
// fot the Tabs and Number Of Tabs.
adapter = new ViewPagerAdapter(getSupportFragmentManager(), Titles,Numboftabs);
// Assigning ViewPager View and setting the adapter
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);
// Assiging the Sliding Tab Layout View
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true); // To make the Tabs Fixed set this true,
// This makes the tabs Space Evenly in
// Available width
// Setting Custom Color for the Scroll bar indicator of the Tab View
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.tabsScrollColor);
}
});
// Setting the ViewPager For the SlidingTabsLayout
tabs.setViewPager(pager);
// End OF OnCreate
}
【问题讨论】:
-
请提供您的 onCreate 方法的代码
-
第一个活动 oncreate 或 Sliding tab?
-
我在创建时添加了我的
标签: android android-theme pagerslidingtabstrip android-tablayout