Simple Android app Can't get a blank activity to use non AppCompat theme -
i've been going through android training tutorials , can't seem simple blank activity apply theme theme.holo.light.
this i've done far:
- set minsdkversion 11 in gradle script , synced project.
applied theme in androidmanifest.xml setting:
android:theme="@android:style/theme.holo.light"
tried applying @ application/activity level , creating custom theme , setting parent.
when running app in emulator crashes error:
java.lang.runtimeexception: unable start activity componentinfo{com.example.test.themetest3/com.example.test.themetest3.mainactivity}: java.lang.illegalstateexception: need use theme.appcompat theme (or descendant) activity.
according documentation default theme 11+ api levels theme.holo can't work , i'm missing something. activity insists on using appcompat themes only. need extend other class within activity?
this activity code (generated creating blank activity).
package com.example.test.themetest3; import android.os.bundle; import android.support.design.widget.floatingactionbutton; import android.support.design.widget.snackbar; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar; import android.view.view; import android.view.menu; import android.view.menuitem; public class mainactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar); setsupportactionbar(toolbar); floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab); fab.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { snackbar.make(view, "replace own action", snackbar.length_long) .setaction("action", null).show(); } }); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.menu_main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } }
thanks assistance :).
your activity extends appcompatactivity
, have use appcompatactivity themes. use in styles.xml
parent="theme.appcompat.light"
and if want use toolbar, can rid of actionbar
using :
parent="theme.appcompat.light.noactionbar"
Comments
Post a Comment