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">
Related
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.
i am trying to hide ActionBar in SplashScreenActivity but i am not able to hide. it always showing.
i tried this: but not worked
protected 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.activity_splash);
or
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.activity_splash);
or
this unfortunately stop app
<application
android:name="info.androidhive.awesomewallpapers.app.AppController"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/FreeWallTheme">
<activity
android:name="info.androidhive.awesomewallpapers.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
In you application's manifest file , set the following property in <application> TAG.
android:theme="#android:style/Theme.NoTitleBar.Fullscreen
Set the following line in your theme:
<item name="windowActionBar">false</item>
Try putting a new theme tag inside activity like below:
<activity
android:name="info.androidhive.awesomewallpapers.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Translucent.NoTitleBar" >
Try this, it worked for me:
getSupportActionBar().hide();
You have to call it in the onCreate method
I am recently facing a problem while creating new android application in both eclipse as well as android studio.
I am using same SDK in both eclipse and android studio.
When I create a new application and i simply run it. The launcher activity was getting loaded twice.
Means, I am getting MainActivity loading twice one on top of another.
OnCreate() method of my MainActivity also got invoked twice.
The code goes like follows
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="21"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<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>
</application>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.out.println("OnCreate Invoked");
}
}
Output
OnCreate Invoked
OnCreate Invoked
Can you please help me in resolving this issue.
Thanks in advance.
It seems you are getting multiple instance of your first activity.
Use this in manifest of 1st activity:
android:launchMode="singleTop"
If I set orientation programatically in onCreate - I can reproduce this issue.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
If needed, set activity orientation in the manifest file like this.
<activity
android:name=".MainActivity"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I've tried to make a "return" button for my app, or as Google call it, Up Button for Low-level Activities.
I wrote everything properly:
in My XML I put the meta-data and the parent activity (Example from Google, I modified the text to my app in my files)
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
in My class I put the next line:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
but when I click this up button, the app closes, then opened again from the main screen.
I want it to return to the main screen without closing (finishing) the app.
Can you help me? Thanks.
Well, according to this guide,
When running on Android 4.1 (API level 16) or higher, or when using ActionBarActivity from the Support Library, performing Up navigation simply requires that you declare the parent activity in the manifest file and enable the Up button for the action bar.
So, I have two Activities: FirstActivity, which is my launcher and parent Activity and SecondActivity, which is my child Activity.
My FirstActivity code:
public class FirstActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main_activity);
Button secondButton = (Button) findViewById(R.id.secondButton);
secondButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(FirstActivity.this, SecondActivity.class));
}
});
}
}
My SecondActivity code:
public class SecondActivity extends ActionBarActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_place_activity);
//enable the ActionBar behaviour
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
My Manifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="20" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.testes.activity.FirstActivity"
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="com.testes.activity.SecondActivity"
android:parentActivityName="com.testes.activity.FirstActivity" >
</activity>
</application>
</manifest>
And this is all I need to have it working your way. I start my FirstActivity, click my Button to go to the SecondActivity, click the ActionBar home button and it goes back to FirstActivity.
I am trying to do some function in Android 2.2.
How can I remove and the borders in white and gray that is shown in below picture?
set Activity's theme to #android:style/Theme.NoTitleBar, in manifest
Add this line to your manifest file where you have declared your activity.
<activity
android:name=".activityName"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" >
</activity>
or progrmatically you can do it by adding
requestWindowFeature(Window.FEATURE_NO_TITLE);
this above line with onCreate method
In your oncreate:
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); // put that line in your oncreate method
setContentView(R.layout.youlayout);
}
you just need to have an edit in manifest as follows
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
this line will not show tiltlebar and will be a fullscreen however if you wants to hide just the title bar than use
android:theme="#android:style/Theme.NoTitleBar"
by means yours manifest should look like this
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.android.some"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".MainActivity"
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>
you can acieve the same by programming as follows
requestWindowFeature(Window.FEATURE_NO_TITLE);
You can do it by two ways
1) Programatically :
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class ActivityName extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
2) Modifying AndroidManifest.xml file:
<activity android:name=".ActivityName"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
</activity>