Hide action bar in Android - android

I am making a android app with android studio with a login at the first site. The problem is that the action bar should be hidden on the login activity but shown on the main activity after the user logged in. Is there a way to do this? I just found tutorials how I can remove it permanently.
Thanks for helping me!

Try this
Add these lines:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0);
For example:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0);
setContentView(R.layout.activity_loguin);
And probably you will need to change your extension class.
I guess you have this:
public class Loguin extends AppCompatActivity
Just change AppCompatActivity. ONLY IF YOU NEED IT
public class Loguin extends Activity

in your Login activity replace android:theme line in androidmanifest like below
<activity
android:name=".Login"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen" // <<== this
>

Hide Action bar from Activity
<activity
android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
No need to add android:theme, it will automatically show you full screen.
Add one line to onCreate() method.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 0);
Thanks

Related

Android: Remove the top bar from an app?

I'm trying to remove the top bar from the app. I try to write in the xml file
<activity
android:theme="#android:style/Theme.Black.NoTitleBar">
</activity>
But it give me the error:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I also try do use the code after OnCreate method:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.your_layout_name_here);
But it also crash....how can i do? Thanks!
You could keep the default theme in AndroidManifest file. There is only one reason you are seeing the title bar.
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize"
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 you could add
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
It is because your activity is extending ActionBarActivity. You could replace by extending Activity for your activity.
public class MainActivity extends Activity
I hope this will solve your problem.

Android Splashscreen - action bar comes for a moment and disappears

In the app I am developing,I am implementing a splashscreen This splashscreen comes at the start of the app. When the splashscreen is launched, the action bar is visible for a small moment say half a second and then disappears. I am not sure why this is happening. Could any one please help me in resolving this issue. I have implemented the following code in the manifest file.
<activity
android:name="com.example.trycatch.SplashscreenActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:noHistory = "true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
And below is the activity file snippet
#Override
protected void onResume() {
setContentView(R.layout.splashscreen);
super.onResume();
}
Could anyone please help me. Thanks for your time.
PS: I am using sherlock actionbar library
Use the following code in the activity(that means in your java file) before setContentView()
requestWindowFeature(Window.FEATURE_NO_TITLE);
add this in your android manifest file
<activity
android:name="com.example.abc.SplashScreen"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.NoActionBar" ></activity>
use following code to disappear Action Bar:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.splash);
more info

Want to launch another activity on start up page without using any listener?

Example I have a java class that has sliding menu code which the java name is Leftandright.java.
Then I have a Main_Activity, but without any listener I want the Application to launch at the LeftandRight.java page. How do I do that?
You can set the starting activity in manifest file, AndroidManifest.xml, by declaring that Activity as a main activity.
<activity
android:name="com.package.LeftandRight" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Or, you can add this code in Main_Activity.java (although this is a VERY BAD approach, do not use unless you know what you're doing)
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startActivity(new Intent(this, LeftandRight.class));
}

"invisible" toggle app without any window shown

I'm writing simple APN toggle app. I wanted to ask how to force android not show any window.
Currently after running my app, for brief time Black screen with app name is shown and then disappears.
Is it possible not to show anything ( only Toast message ) ?
public class ApnSwtichActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (toggleAPN()){
Toast.makeText(this, "Apn switched", Toast.LENGTH_SHORT).show();
}
this.finish();
}}
Sounds like you want an activity without a UI
How to launch an Activity without a UI?
You'll probably want to use
android:theme="#android:style/Theme.NoDisplay"
I don't think this is possible exactly as you want. You can hide title bar like this: add android:theme="#android:style/Theme.Light.NoTitleBar.Fullscreen" in your manifest:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:name=".TestActivity"
android:theme="#android:style/Theme.Light.NoTitleBar.Fullscreen"
>
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You could create an activity, make it transparant and give it the parameters FLAG_NOT_TOUCH_MODAL & FLAG_NOT_TOUCHABLE
(FLAG_NOT_TOUCH_MODAL passes any touch input you give to your activity to the underlying screen, FLAG_NOT_TOUCHABLE negates any touch input commands for the activity)
Don't forget to make your activity autoclose after you're done

Android App - disappearance of app GUI

I'm trying to create a simple app, whose main task is to open the browser on defined URL.
I've created first Activity:
public class MyActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
Intent myIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://my.url.tld"));
startActivity(myIntent);
}
Here's my AndroidManifest.xml:
<manifest ...>
<application ...>
<activity android:name=".MyActivity" ...>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
This code is fully functional, but before it opens the browser, it displays a black background - blank app GUI. I didn't figured out, how to go directly do the browser (without displaying the GUI).
Anyone knows?
Add this theme declaration to your activity definition in you manifest
<activity android:name=".MyActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
>
Be careful with this, you must call finish(); from your activity after you are done with it otherwise users could get stuck with an invisible activity that prevents them from interacting the phonetop.

Categories

Resources