I'm making an app that I want in fullscreen (well, it can have the icons on top such as signal, battery etc, but no titlebar). It's in landscape and I'm testing on my "ye olde" Samsung Galaxy Ace.
When using the regular android:theme="@style/AppTheme it's fine, but has the titlebar. Whenever I've tried the usual solutions (changing it to a fullscreen, no titlebar style - don't have the code on me) it'll load up, but the screen itself stays blank, until it crashes a few seconds later.
I'll paste the relevant files and logcat...
Manifest...
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.myname.MainActivity"
android:screenOrientation="landscape"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MainActivity...
package com.example.myname;
import com.example.simpletimer.R;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
// if (savedInstanceState == null) {
// getSupportFragmentManager().beginTransaction()
// .add(R.id.container, new PlaceholderFragment())
// .commit();
// }
}
@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.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
Logcat...
09-20 20:37:56.890: I/ApplicationPackageManager(15836): cscCountry is not German : BTU
09-20 20:37:56.960: W/dalvikvm(15836): threadid=1: thread exiting with uncaught exception (group=0x40018578)
09-20 20:37:56.984: E/AndroidRuntime(15836): FATAL EXCEPTION: main
09-20 20:37:56.984: E/AndroidRuntime(15836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.simpletimer/com.example.myname.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
09-20 20:37:56.984: E/AndroidRuntime(15836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
09-20 20:37:56.984: E/AndroidRuntime(15836): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
09-20 20:37:56.984: E/AndroidRuntime(15836): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-20 20:37:56.984: E/AndroidRuntime(15836): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
09-20 20:37:56.984: E/AndroidRuntime(15836): at android.os.Handler.dispatchMessage(Handler.java:99)
09-20 20:37:56.984: E/AndroidRuntime(15836): at android.os.Looper.loop(Looper.java:130)
09-20 20:37:56.984: E/AndroidRuntime(15836): at android.app.ActivityThread.main(ActivityThread.java:3687)
09-20 20:37:56.984: E/AndroidRuntime(15836): at java.lang.reflect.Method.invokeNative(Native Method)
09-20 20:37:56.984: E/AndroidRuntime(15836): at java.lang.reflect.Method.invoke(Method.java:507)
09-20 20:37:56.984: E/AndroidRuntime(15836): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
09-20 20:37:56.984: E/AndroidRuntime(15836): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
09-20 20:37:56.984: E/AndroidRuntime(15836): at dalvik.system.NativeStart.main(Native Method)
09-20 20:37:56.984: E/AndroidRuntime(15836): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
09-20 20:37:56.984: E/AndroidRuntime(15836): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
09-20 20:37:56.984: E/AndroidRuntime(15836): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
09-20 20:37:56.984: E/AndroidRuntime(15836): at com.example.myname.MainActivity.onCreate(MainActivity.java:30)
09-20 20:37:56.984: E/AndroidRuntime(15836): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-20 20:37:56.984: E/AndroidRuntime(15836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
09-20 20:37:56.984: E/AndroidRuntime(15836): ... 11 more
Any help would be greatly appreciated - thanks!
EDIT AND MY ANSWER
Okay, I tried the two solutions listed below but unfortunately couldn't find a theme that worked, and the posted ones weren't found in my resources. So I put the following code in my MainActivity:
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
This is just after the
setContentView(R.layout.activity_main);
I'll still accept both answers below (if I can) as, whilst they did point me in the right direction but I couldn't get them to work (which was my fault), I'm sure they'd help others.