您需要在Android上的此活动中使用Theme.AppCompat主题(或后代) [英] You need to use a Theme.AppCompat theme (or descendant) with this activity on Android
本文介绍了您需要在Android上的此活动中使用Theme.AppCompat主题(或后代)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在活动"中有此内容:
I have this in Activity :
public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener{
private Toolbar mToolbar;
private FragmentDrawer drawerFragment;
private RecyclerView recyclerView;
private IsAdapter isAdapter;
private List<Is> isList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
isList = new ArrayList<>();
isAdapter = new IsAdapter(this, isList);
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(this, 1);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.addItemDecoration(new GridSpacingItemDecoration(2, dpToPx(10), true));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(isAdapter);
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
drawerFragment.setDrawerListener(this);
// display the first navigation drawer view on app launch
displayView(0);
}
我使用自己的主题(很重要),效果很好,然后我对代码进行了一些更改,现在出现此错误.我怎样才能解决这个问题?预先感谢.
I'm using my own theme (which is material), It was working well, then I made some changes in the code, now I get this error. How can I fix this? Thanks in advance.
我的清单文件中有:android:theme="@style/MyMaterialTheme">
我用谷歌搜索,解决方案说将AppCompatActivity
更改为Activity
或FragmentActivity
.当我这样做时,这些行会出现错误:
I googled, the solutions say change AppCompatActivity
to Activity
or FragmentActivity
. When I do that, I get error at these lines :
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
这是我的styles.xml:
Here is my styles.xml :
<resources>
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
推荐答案
更改此
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
对此
<style name="MyMaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
完整代码:
<resources>
<style name="MyMaterialTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
,然后clean
项目,然后rebuild
它.
这篇关于您需要在Android上的此活动中使用Theme.AppCompat主题(或后代)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文