[英]why do android insists that I already have action bar?
請按照此處的教程進行操作: http : //www.android4devs.com/2015/01/how-to-make-material-design-sliding-tabs.html#嘗試執行材料設計滑動選項卡我按照指示進行了所有操作。
但是,當我運行該應用程序時,它給了我以下消息:
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.
我試圖解決這個問題,並嘗試了很多事情,但都沒有成功。
最終我來到了這個問題stackoverflow.com/questions/29790070/upgradeed-to-appcompat-v22-1-0-and-now-getting-illegalargumentexception-appcompa並接受了回答。
我將styles.xml更改如下:
<style name="AppBaseTheme" parent="Theme.AppCompat.NoActionBar">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>
盡管如此,它仍然給我同樣的錯誤信息。
只是為了完成,這是我的活動:
public class MainActivity extends AppCompatActivity {
private ViewPager mViewPager;
private HomeTabsPagerAdapter mPageAdapter;
private Toolbar mToolbar;
private SlidingTabLayout mTabs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setViewsClassMembers();
setSupportActionBar(mToolbar);
mPageAdapter = new HomeTabsPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mPageAdapter);
// Assiging the Sliding Tab Layout View
mTabs.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
mTabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.tabsScrollColor);
}
});
// Setting the ViewPager For the SlidingTabsLayout
mTabs.setViewPager(mViewPager);
}
private void setViewsClassMembers() {
mViewPager = (ViewPager) findViewById(R.id.pager);
mToolbar = (Toolbar) findViewById(R.id.tool_bar);
mTabs = (SlidingTabLayout) findViewById(R.id.tabs);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()) {
case R.id.action_new_request:
startNewRequestActivity();
break;
}
return super.onOptionsItemSelected(item);
}
private void startNewRequestActivity() {
Intent intent = new Intent(this, NewRequestActivity.class);
startActivity(intent);
}
}
誰能看到問題出在哪里? 為什么Android堅持要求我已經擁有操作欄?
看到它: https : //stackoverflow.com/a/26515159
<item name="windowActionBar">false</item>
在您的styles.xml中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.