3

I am using AppTheme.NoActionBar. I am trying to remove title bar from app.

Here what i have already tried.

Tried settings android:theme="@style/Theme.NoTitleBar" this gives me error cannot resolve symbol

Tried adding requestWindowFeature(Window.FEATURE_NO_TITLE); in onCreate method before setting ContentView it doesn't affect anything

Here are the post i posts i already tried

How to hide the title bar for an Activity in XML with existing custom theme

Remove app title bar android

What i am trying to do is i am creating a custom UI and want the app full screen(want to show notification bar).

Also my app is targeted for Api level 10 and above

Update Here are few more things i tried https://chat.stackoverflow.com/rooms/113175/discussion-between-arthur-leao-and-akash-kumar suggested by @ArhturLeao

Update 2

Tried @android:style/Theme.NoTitleBar on a new sample project worked as expected(had to extened Activity class instead of AppCompactActivity class)

Tried same with project i am having issue and it still shows Blank TitleBar.

Here is the project i am having trouble with https://github.com/skywebdeveloper/Tikona-Session-Manager/tree/design

**Update 3 **

onCreate Method

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        CookieHandler.setDefault(new CookieManager());

        popupLoader = new ProgressDialog(this);

        url = getSharedPreferences("url", MODE_PRIVATE);
        sessionPreference = getSharedPreferences("session", MODE_PRIVATE);

        sessionStart = (TextView) findViewById(R.id.sessionStartValue);
        sessionDuration = (TextView) findViewById(R.id.sessionDurationValue);
        sessionUsage = (TextView) findViewById(R.id.sessionUsageValue);


        logout = new AlertDialog.Builder(this);
        logout.setMessage("Are you sure you want logout?").setTitle("Confirm Logout");
        logout.setPositiveButton("Logout", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //Call logout uri
                logout();
            }
        });
        logout.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //Do nothing
            }
        });

        logout.create();

        //fetchSessionDetails();
        getURLs();

    }

style.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->

        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>
Community
  • 1
  • 1
Skyyy
  • 1,539
  • 2
  • 23
  • 60

4 Answers4

4

I've explored your project and found your problem: by style you are of course removing ActionBar, but you've forgot that you have a Toolbar in your activity_main.xml, and more than that you are setting it as a default ActionBar for your Activity by next code:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

Then of course you will have your ActionBar always appearing :) So all you need is just to add getSupportActionBar().hide(); in activities which you want to be fullscreen:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().hide();

And it should work as expected.

romtsn
  • 11,704
  • 2
  • 31
  • 49
  • Thanx it worked. Why do i have two xml layout named activity and content. I do all the work in content layout. – Skyyy Jun 01 '16 at 18:57
  • Cause in `activity_main.xml` you have an `AppBarLayout` + `include` and that `include` is including your `content_main` exactly. So it was done to divide content and appbar:) – romtsn Jun 01 '16 at 19:58
1

Just add these to your style:

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

Here is a complete example:

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

</resources>

MainActivity.java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

I've just created a new project using the "Blank Activity" template and added the two lines to the style - everything else is using the default configuration.

Samuil Yanovski
  • 2,837
  • 17
  • 19
  • Not Working... Title bar is still shown. These example work perfectly fine with new sample project i created. But not working with the current project i am working on. Don't know the reason. – Skyyy May 30 '16 at 15:15
  • @AkashKumar, could you post your style and the Activity (or at least the onCreate method)? I'll try to figure out what is going wrong. – Samuil Yanovski May 30 '16 at 16:06
  • This is repo of the project i am having issue with https://github.com/skywebdeveloper/Tikona-Session-Manager/tree/design – Skyyy May 31 '16 at 12:12
  • Thanks, I'll check it up. – Samuil Yanovski May 31 '16 at 15:39
  • @AkashKumar, the Tikona project is actually using a NoActionBar. Instead the activity's layout contains a Toolbar, which is used as an ActionBar. You can't remove it via the styles, because the View is added from the layout. If you want to remove it look for the android.support.design.widget.AppBarLayout and the android.support.v7.widget.Toolbar elements in the activity_main.xml. You can either hide them (visibility: gone) or remove them completely (the end result will be a lot cleaner, but you'll have to remove any code references to them too). – Samuil Yanovski Jun 01 '16 at 16:34
0

Try this:

Add

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

To your onCreate Method, after super.onCreate and before setContentView

  • App crash with `java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.` – Skyyy May 27 '16 at 18:27
  • One question: when you added this.requestWindowFeature(Window.FEATURE_NO_TITLE); Where did you inserted it? – Arthur Leão May 27 '16 at 18:29
  • And try adding android:theme="@style/AppTheme" to your android manifest, below – Arthur Leão May 27 '16 at 18:35
  • In my `MainActivity` Class inside `onCreate` method before `super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);` Also tried adding `android:theme="@style/AppTheme"` inside Application attribute – Skyyy May 27 '16 at 18:38
  • Does it still crash with java.lang.IllegalStateException? – Arthur Leão May 27 '16 at 18:40
  • Don't know why you're getting these errors. Let's try ad different aproach, i edited my response. Delete these changes we tried. – Arthur Leão May 27 '16 at 18:49
  • Should i set my theme back to AppCompact or continue with same – Skyyy May 27 '16 at 18:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/113175/discussion-between-arthur-leao-and-akash-kumar). – Arthur Leão May 27 '16 at 18:53
0

This code is working for me and doesnt have a App Bar

I had replaced it with a Toolbar.

Find out what you are missing.

I think you are not applying your AppTheme.NoActionBar to your MainActivity in Manifest.

MainActivity.java

 public class MainActivity extends AppCompatActivity {

 EditText editUsername,editPassword;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

       Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
       toolbar.setTitle("Login");
       setSupportActionBar(toolbar);

       editUsername=(EditText)findViewById(R.id.username);
       editPassword=(EditText)findViewById(R.id.password);


     }
   }

styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay"  
     parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

Manifest.xml

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

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

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

 </manifest>
Ashish Shukla
  • 1,027
  • 16
  • 36
  • Still not working TitleBar is still shown. If i use this code with new project it work fine. But with my current project its not working. This is the repo of the project i am having issue with https://github.com/skywebdeveloper/Tikona-Session-Manager/tree/design – Skyyy May 31 '16 at 12:11
  • Can you try File->Invalidate Caches/Restart Option -> Invalidate and Restart and then check your app – Ashish Shukla May 31 '16 at 12:58