DaniFG
DaniFG

Reputation: 33

How to make the actionbar disappear in Android Studio?

I need to make the action bar disappear from the screen, I've tried everything I've been able to find online, but nothing seems to work. I've tried creating my own style, which doesn't do anything, getActionbar().hide(), which gives me an error and doesn't compile, and requestWindowFeature(Window.FEATURE_NO_TITLE);, which also doesn't do anything. I really need to get rid of that action bar. I'm using a sensorLandscape orientation, but I've already tried changing it and it doesn't change anything.

The manifest:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.tanques">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen>
        <activity android:name=".MainActivity" android:screenOrientation="sensorLandscape" android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
    </application>

</manifest>

My own style:

<resources>

    <!-- Base application theme. -->

    <style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>
</resources>

MainActivity.java

package com.example.tanques;

import android.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity implements JoystickView.JoystickListener, JoystickHorizontal.JoystickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Button ShootLeft= findViewById(R.id.ShootLeft);
        Button ShootRight= findViewById(R.id.ShootRight);
        ShootLeft.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){
            Log.d("Button","ShootLeft");
        }});
        ShootRight.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){
            Log.d("Button","ShootRight");
        }});
    }

    @Override
    public void onJoystickMoved(float Percent, int source) {
        switch(source){
            case R.id.JoystickLeft:
                Log.d("Joystick", "JoystickLeft" + " Percentage: " +Math.round(Percent));
                break;
            case R.id.JoystickRight:
                Log.d("Joystick", "JoystickRight" + " Percentage: " +Math.round(Percent));
                break;
            case R.id.JoystickTurret:
                Log.d("Joystick", "JoystickTurret" + " Percentage: " +Math.round(Percent));
                break;
        }
    }
}

Upvotes: 3

Views: 563

Answers (1)

daniel.jbatiz
daniel.jbatiz

Reputation: 447

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.tanques">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
    </application>

</manifest>

styles.xml

<resources>

    <!-- Base application theme. -->

    <style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar"/>

</resources>

Put this inside your onCreate() in MainActivity.java before setContentView()

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //add this two lines to your code to hide the system bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN , WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_main);

    //this hides the navigation bar at the bottom of your device
    hideNavigationBar();

    final Button ShootLeft= findViewById(R.id.ShootLeft);
    Button ShootRight= findViewById(R.id.ShootRight);
    ShootLeft.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){
        Log.d("Button","ShootLeft");
    }});
    ShootRight.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v){
        Log.d("Button","ShootRight");
    }});
}

create hideNavigationBar() method and call it in the onCreate()

private void hideNavigationBar(){
    getWindow().getDecorView()
               .setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_FULLSCREEN |
                    View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
               );
}

Upvotes: 1

Related Questions