Not able to hide ActionBar (Android) - android

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

Related

Launcher Activity is opening twice in my new SDK

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>

How does an android program understands which class or/and activity to call first?

As i am new to android programming, I don't know how to call a certain class and/or certain activity first.
For example i have two classes viz. 1) Login.java 2) Create.java and two xml files associated with them are activity_main.xml and create_new.xml respectively.
So how can i make Login.java run first with activity_main.xml as screen?
in login java use this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);}
in create java us this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_new);
in androidmanifest
<activity
android:name=".Login"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and another activities
<activity android:name=".MainActivity" ></activity>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.your.package"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.your.package.activity.Login"
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.example.your.package.activity.Create"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
In this case, the intent-filter of LOGIN activity specifies that the intent with action of MAIN and category of LAUNCHER will be caught by it, aka it is where the application starts.
Afterwards,
public class Login extends Activity
{
//honestly I'd name this class LoginActivity and same in the XML
#Override
public void onCreate(Bundle saveInstanceState)
{
super.onCreate(saveInstanceState);
setContentView(R.layout.activity_main);
}
....
}
Also look at this example to learn how to use Fragments:
NullPointerException accessing views in onCreate()
from the intent filters you decalre in the android manifest file of your project;see the image
You declare an intent filter in the activity tag something like shown in the image for making it the first activity of your application.and if there are other activities in your app having intent filters than you have to just change the capital letter MAIN to DEFAULT in the intent filter tag
You will find AndroidManifest file like in the following image in your project

why this screen, while app opens every time

Here I am getting this screen every time just like a splash for few seconds and then opening the home activity.I don't want to this screen in my app. How to fix it.
Here is my manifest file
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.asdf.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>
For your Information, I am using Support Library for developing.
I changed the app Style to "#android:style/Theme.Translucent.NoTitleBar" then this screen is not showing but It has the impact on other UI components of the same App like.. Spinner, text-view etc.
Add this line in your style.xml
<style name="AppTheme" parent="android:style/Theme.Holo">
<item name="android:windowDisablePreview">true</item>
try this..well previous one should work.It worked for me
If you want to remove the title bar, then use the following in your Activity initialization:
#Override
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_main);
...
move Intent-filter code to whichever activity of your application. and remove that activity code.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Hope it will work

In Android 2.2 how can I remove

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>

Android launch other activity before launching splash activity

I'm developing an application in android, where the app starts with a splash screen. I declared the splash activity as launcher activity in the manifest, but when I start my app, the launcher always shows up a grey activity with no content instead of the actionbar with the title of my app. The splash activity always comes up after one or two seconds.
Can anyone explain this behavior to me?
Here's my manifest:
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:logo="#drawable/navigation"
android:theme="#style/Theme.Sherlock.Light" >
<activity
android:name="de.test.basic.SplashActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity></application>
And here's the onCreate() method of the SplashActivity:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.spash_screen);
img = (ImageView) findViewById(R.id.imageView1);
img.setImageResource(R.drawable.splashscreen);
getActionbar().hide();
slideMenu.setSlidingEnabled(false);
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
startActivity(new Intent(SplashActivity.this,
OtherActivity.class));
overridePendingTransition(android.R.anim.fade_in,
android.R.anim.fade_out);
finish();
}
}, SPLASH_DELAY);
}
Thanks for any help :)
Looks like its a bug in the api!
Simply add this in your starter activity declared in your manifest:
<activity
...
android:theme="#style/Theme.NoActionBar" >
<intent-filter>
...
</intent-filter>
</activity>
And if you are using ActionBarSherlock
<activity
...
android:theme="#style/Theme.Sherlock.NoActionBar" >
<intent-filter>
...
</intent-filter>
</activity>
Your question is rather similar than this one

Categories

Resources