3

I am really frustrated right now and read a ton - maybe you can help me out. Why is Android Studio still showing me "Main2Activity" with the titlebar?

Here is my Manifest:

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

<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>
    <activity android:name=".Main2Activity"
        android:theme="@android:style/Theme.Light.NoTitleBar"></activity>
</application>

I know it is really a small issue but I am unable to figure it out...

Sources I used:

https://developer.android.com/guide/topics/ui/look-and-feel/themes.html

Android theme not being set

Apply a theme to an activity in Android?

EDIT Current State: enter image description here

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

Is working but disables the ActionBar for every Activity!

Goal: activity_main2 should not have an ActionBar.

SOLVED It is just a bug from Android Studio. In the Preview it won't disable the AppBar but as soon as you play the App on your phones it works!

Taka Incur
  • 35
  • 1
  • 6
  • Does your XML layout have a Toolbar? – OneCricketeer Dec 21 '17 at 00:58
  • Tried this? https://stackoverflow.com/a/25365193/2308683 – OneCricketeer Dec 21 '17 at 01:03
  • Yes the goal is that my layout will have a toolbar. At the moment to put it in a simple case: I got 2 activitys. One of them will keep the "default" bar and the other one will get a toolbar. Therefore Fullscreen is no option for me sry – Taka Incur Dec 21 '17 at 01:21
  • My point is that you're still seeing the bar because the Activity layout told it to load one, even though the theme doesn't have one – OneCricketeer Dec 21 '17 at 01:22
  • Sorry, I am confused now: Yes, the default is that my App hat an AppBar. but giving an activity another theme in the Manifest doesn't change anything. And I don't know why... – Taka Incur Dec 21 '17 at 01:29
  • `` in the XML layout will always be displayed. Regardless of the theme settings. If you also use a theme with a ActionBar, you'll get two bars. – OneCricketeer Dec 21 '17 at 01:32
  • Can you just add the layout of both activities to the question? Also a screenshot of both? And highlight the difference you want – OneCricketeer Dec 21 '17 at 01:33
  • My goal is to have an activity without anything. By using ` – Taka Incur Dec 21 '17 at 01:35

2 Answers2

1

To Hide the Action Bar add the below code in Values/Styles

<style name="CustomActivityThemeNoTitle" parent="@android:style/Theme.Light">
    <item name="android:windowNoTitle">true</item>
</style>

Then in your AndroidManifest.xml file add the below code in the required activity:

<activity android:name=".Main2Activity"
    android:theme="@style/CustomActivityThemeNoTitle"></activity>

Alternatively, you can call this.requestWindowFeature(Window.FEATURE_NO_TITLE); in the onCreate method for your activity. For example:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_signup);
    ...
}
JMA
  • 1,781
  • 9
  • 18
0

Try this

<style name="generalnotitle" parent="general">
    <item name="android:windowNoTitle">true</item>
</style>
Ratilal Chopda
  • 4,162
  • 4
  • 18
  • 31