Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 953
Taka Incur Avatar asked Aug 22 '26 19:08

Taka Incur


1 Answers

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);
    ...
}
like image 84
JMA Avatar answered Aug 24 '26 07:08

JMA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!