我创建了一个全新的Android项目,其中包含“Hello World”TextView的空白活动。当我隐藏ActionBar然后在AVD上运行时,应用程序停止。错误看起来像这样:“不幸的是,已经停止了”
我已经尝试过这种隐藏动作栏的方法,但对我没有任何作用:
1)<activity android:theme="@android:style/Theme.NoTitleBar.Fullscreen"....>
2)在onCreate()
方法getActionBar()。hide();
以下是logcat中的红色字符串:
02-13 18:42:43.373 2123-2123/? E/Trace﹕ error opening trace file: No such file or directory (2)
02-13 18:42:43.383 794-948/? E/SurfaceFlinger﹕ ro.sf.lcd_density must be defined as a build property
02-13 18:42:43.523 2123-2123/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{styleru.it_lab.reaschedule/styleru.it_lab.reaschedule.loginActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:309)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:278)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:252)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at styleru.it_lab.reaschedule.loginActivity.onCreate(loginActivity.java:13)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
02-13 18:42:43.733 794-947/? E/SurfaceFlinger﹕ ro.sf.lcd_density must be defined as a build property
答案 0 :(得分:0)
你可以在setcontentview
之前使用requestWindowFeature requestWindowFeature(Window.FEATURE_NO_TITLE);
答案 1 :(得分:0)
通过更改
解决了这个问题 public class MainActivity extends ActionBarActivity
到此:
public class MainActivity extends Activity