Taka Incur
Taka Incur

Reputation: 45

AndroidManifest - Set theme for activity

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!

Upvotes: 3

Views: 4502

Answers (2)

JMA
JMA

Reputation: 1825

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);
    ...
}

Upvotes: 1

Ratilal Chopda
Ratilal Chopda

Reputation: 4220

Try this

<style name="generalnotitle" parent="general">
    <item name="android:windowNoTitle">true</item>
</style>

Upvotes: 0

Related Questions