Fullscreen Android "Unfortunately application has stopped" Why? - android

I wanted to implement in my application the fullscreen. I found this code to do it:
public class FullScreen extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
or through the AndroidManifest.xml
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
well none goes. Both makes my app crash when I launch it. The error is "Unfortunately application has stopped". Anyone knows the problem?

Try this code to make your activity FULL_SCREEN
Looking for find: styles.xml in res\values\ add
<style name="NoTitle" parent="AppBaseTheme">
<item name="android:windowNoTitle">true</item>
</style>
Open file Manifest
Looking for application
Add
android:theme="#style/NoTitle">
It looks like:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/NoTitle" >

put your code BEFORE super.onCreate(savedInstanceState)

This worked for me.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>

Related

Activity does not show title bar in Android Studio

I have create demo application in Android Studio with two Activity. In First Activity Show Title Bar in preview as well as in emulator but on second Activity does not show Title Bar in Emulator but it display in preview. I have used API 22 in Android Studio.
Please help me....thanx in advn
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/BaseTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DrawingActivity"
android:label="#string/app_name"
android:theme="#style/BaseTheme"
android:screenOrientation="portrait" />
</application>
Theme style file like this....
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="BaseTheme" parent="AppTheme">
<item name="colorPrimary">#color/action_bar_backgound</item>
</style>
I have also try this...
First Activity Work's fine so I have set that in Second Activity as a setContentView(R.layout.activity_main);
MainActivity.java
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void buttonAction(View v) {
Intent intent = new Intent(MainActivity.this, DrawingActivity.class);
startActivity(intent);
}
}
DrawActivity.java
public class DrawingActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
What you are facing is a bug related to the API 22(5.1) SDK.
Kindly refer the following links for the details on the bug in which the Action Bar is not displayed:
https://code.google.com/p/android/issues/detail?id=159793
https://code.google.com/p/android/issues/detail?id=159780
What you can do for now
Either revert back to API 21 if possible or,
Select API 21 in the compile with (render with) option in Android Studio.
Hope this helps.

Trying to go full screen crashes my app

This is my a portion of my android manifest.xml
<application
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
And this is part of my onCreate()
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Whenever I attempt to make the app run in full screen landscape it crashes upon launching. However if I remove the lines that set the orienation and such the apps runs just fine.
And the Logcat data: http://pastebin.com/D9zRVfBy
If you're extending ActionBarActivity then you have to use one of the support library themes, i.e. Theme.AppCompat. It tells you exactly that in the stack trace.
For example:
<application
....
android:theme="#style/Theme.AppCompat"
Of course you can also use your own theme, but it would have to inherit from Theme.AppCompat

android activity call requestWindowFeature first and show the title

My Activitys use a theme which set android:windowNoTitle = true.But I have to show the title in some activities. I want show the title in my activity by call requestWindowFeature(), but it's not work! Any help would be great.
Thanks.
ps:
My activitys hava to be switched between two themes.The homeActivty use the actionbar and others no title.These activtys are use the same themes.So when before use requestWindowFeature() it's been hiding, and i just want show it now.
Here is my codes:
Defined theme:
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowAnimationStyle">#style/activityAnimation</item>
<item name="android:windowNoTitle">true</item>
<!-- <item name="android:background">#color/background_holo_light</item> -->
</style>
And use the theme in application:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Get and change the theme if necessary:
int mThemeId = mSettingPreferences.getInt(MySettings.THEME_ID, -1);
if (-1 != mThemeId) {
this.setTheme(mThemeId);
}
// do something to show the title
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.yourlayout);
You don't need to apply any Theme if you use this.
you have to use this method before your setContentView method...
requestWindowFeature(Window.FEATURE_NO_TITLE);
OR
And yes you can add theme in Manifest file in which Activity you don't want to Title..Then use this..
<activity
android:name=".activity name"
android:theme="#android:style/Theme.Black.NoTitleBar"
android:screenOrientation="potrait" >
</activity>
first change this:
if (mThemeId != -1) {
this.setTheme(mThemeId);
}
and after that you can use
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
<activity
android:name=".HistoryImage"
android:screenOrientation="sensorPortait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
</activity>
<activity
android:name=".HistoryVideo"
android:screenOrientation="sensorPortait" >
</activity>
<activity
android:name=".HistoryVideo_2"
android:theme="#android:style/Theme.Black.NoTitleBar"
android:screenOrientation="sensorPortait" >
</activity>
you must call requestWindowFeature(); before setContentView()
The activities in which you don't want to show the title bar. just do this to hide the title bar. befor setcontentView requestWindowFeature(Window.FEATURE_NO_TITLE);
I hope this will help you
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_page);

How set Theme in main activity api 7?

I offer my users a light and dark option for theming.
The error in the Log:
Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
The error occurs in setContentView(R.layout.activity_main); in the MainActivity.
MainActivity
public class MainActivity extends SherlockFragmentActivity {.....public static int globalTheme;
Context context;
protected void onCreate(Bundle savedInstanceState) {
context = getApplicationContext();
mySharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
Editor editor = mySharedPreferences.edit();
editor.putBoolean("proxy", false);
editor.commit();
if (mySharedPreferences.getString(Preferences.PREF_THEME, "1").trim().equals("1"))
globalTheme = R.style.Sherlock___Theme;
else
globalTheme = R.style.Sherlock___Theme_Light;
setTheme(globalTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
I did not add something in the manifest, because the themes should be changed dynamically
AndroidManifest.xml
<uses-sdk android:minSdkVersion="7"
/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:name="com.belasheuski.activities.MyApplication"
>
<activity
android:name="com.belasheuski.activities.MainActivity"
android:label="#string/name_main"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This error occurs on API 7. On API 15 all works very well.
I'm setting this in this way ...
setTheme(isLightTheme ? R.style.MyApp_Light : R.style.MyApp);
where the style definition are looking like ...
<style name="MyApp.Light" parent="#style/Theme.Sherlock.Light.ForceOverflow">
<item name="overlayedActionBarBackground">#color/overlayedActionBarLight</item>
...
</style>
<style name="MyApp" parent="#style/Theme.Sherlock.ForceOverflow">
<item name="overlayedActionBarBackground">#color/overlayedActionBarDark</item>
...
</style>
That works pretty fine. So I think you took the wrong style definition from ABS.
Cheers!
The error message tells you what is wrong, your theme must be "Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative."
This is occuring on API 7 but not on API 15 because API 15 has native ActionBar support, so that is used, while this is not the case on API 7, and hence the need for the theming.
Going from the error:
You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative."
It seems that your custom style does not inherit from a Sherlock theme. Check the styles.xml file in your values folder and ensure they inherit from one of those.

Prevent a hidden status bar from reappearing after screen lock

i want to hide status bar in my application to make it fullscreen, so i use this example Hide Notification bar - it works fine. But if i lock the screen and then unlock it, the status bar appears, how to solve this problem?
To hide the Android Status Bar and the Application Title bar, add the following to the Manifest file:
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
Example:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.vogella.android.temperature"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".Convert"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
UPDATED
Also try to put this code in your relevant activity after returning from the lockscreen:
public class FullScreen extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
If security is not an issue, you can disable the lock screen while your app is running. Add the following line to the manifest:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
In your activity, you can do as follows:
public class MyActivity extends Activity {
private KeyguardLock lock;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Disable lock screen.
KeyguardManager keyGuardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
lock = keyGuardManager.newKeyguardLock("MyActivity");
lock.disableKeyguard();
}
#Override
protected void onDestroy() {
super.onDestroy();
// Reenable the lock screen again.
lock.reenableKeyguard();
}
}
Only add this to the styles
<style name="AppTheme" parent="Theme.Design.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowFullscreen">true</item>
</style>
use this code in onCreate() before setContentView()
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Write this code in your aapplication's mainfest.xml file in application tag as below:
<application android:name="application package"
android:label="application name" android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen">

Categories

Resources