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!
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);
...
}
Try this
<style name="generalnotitle" parent="general">
<item name="android:windowNoTitle">true</item>
</style>
Related
I am using activity and so I have to create my own toolbar and add it. Only problem is, the current default titlebar is not being removed even though I modified my styles.xml accordingly.
This is my file:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
I have clearly stated "Theme.AppCompat.Light.NoActionBar"
I even tried this in one of my activity classes:
public class ViewCars extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.carspage);
}
}
And it crashes!
This is the actual error from the Android Studio:
java.lang.RuntimeException: Unable to start activity ComponentInfo{benj.samplesapp/benj.samplesapp.ViewCars}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
My android manifest:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light">
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
How do I remove the old one?
I think the problem is that you defined a style with no action bar but never applied it to your activity actually in your manifest file you are applying #style/Theme.AppCompat.Lightto your whole application and that is why your activity gets an action bar. so in your manifest file change your activity declaration to
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme:"#style/AppTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and remove this.requestWindowFeature(Window.FEATURE_NO_TITLE);from your ViewCars class
While working on the Big Nerd Ranch's Criminal Intent project when I updated my AppCompat library from API 19 to API 21 I lost ActionBar. I have tried changing themes around but I can't find a way to get ActionBar.
The full source code is available here.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sudhirkhanger.app.criminalintent" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity android:name=".CrimeListActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".CrimePagerActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
Thanks.
To use appcompat-v7, you must inherit from ActionBarActivity. CrimeListActivity inherits from SingleFragmentActivity, which in turn inherits from FragmentActivity, not ActionBarActivity.
I also had that problem I moved the whole line (android:theme="#style/AppTheme) and its works! The theme is a dark theme which looks better.
I came across this issue as well.
The solution is remove the style tag from the manifest.xml (android:theme="#style/AppTheme").
It will use the holo theme, but with the Action Bar.
I'm uncertain of the expected behavior when using ActionBarCompat and supportRequestWindowFeature(Window.FEATURE_NO_TITLE). I see two different behaviors depending on Android version:
On a Android ICS (possibly also from Android 3.0?) device using ActionBarCompat a call to supportRequestWindowFeature(Window.FEATURE_NO_TITLE) would hide the combined titlebar/actionbar
On a Android 2.3 device the actionbar is still visible even though supportRequestWindowFeature(Window.FEATURE_NO_TITLE) is called.
Some additional information: My activities extend android.support.v7.app.ActionBarActivity and my app uses the #style/Theme.AppCompat.Light theme. supportRequestWindowFeature(Window.FEATURE_NO_TITLE) is called before setContentView(). I never make any call to either getSupportActionBar().show() or hide().
So, what's the expected behavior? When I used ABS a call to requestWindowFeature(Window.FEATURE_NO_TITLE) would hide the titlebar/actionbar regardless of Android version.
How would I go about having an android app where some activies use an actionbar while others have none? Should they not extend the same base class?
So I've found a solution to this but it uses styles applied via the AndroidManifest (and therefore needs no code). Keep in mind that this will almost definitely only work if you're using the AppCompat library.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="..."
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="19" />
<application
android:allowBackup="false"
android:icon="#drawable/launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar">
<activity
android:label="#string/log_in"
android:name=".activities.LogInActivity"
android:parentActivityName=".activities.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.MainActivity" />
</activity>
<activity
android:label="#string/app_name"
android:name=".activities.MainActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="#string/sign_up"
android:name=".activities.SignUpActivity"
android:parentActivityName=".activities.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".activities.MainActivity" />
</activity>
</application>
</manifest>
Note how I've got a global theme applied directory to the <application> tag, and then also a theme that's individually applied to my MainActivity class through its own <activity> tag. That is the only Activity where I want the Action Bar to be hidden; everywhere else I want it to be visible (which is why I don't have individual themes applied to any of my other Activities as I instead let them inherit from the global application theme).
But you'll quickly find that Theme.AppCompat.Light.NoActionBar doesn't actually exist. This is because I had to create that style myself, which requires two different styles.xml files:
values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.AppCompat.Light.NoActionBar" parent="Theme.AppCompat.Light">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
values-v11/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.AppCompat.Light.NoActionBar" parent="Theme.AppCompat.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
You must use two different styles.xml files for this as the android:windowActionBar flag didn't exist before Android API version 11.
I want to override a application theme on a particular activity, but its not working for me
This is code on my Manifest.xml:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.Light" >
<activity
android:theme="#style/MyTheme"
android:name="com.ssdevnet.Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ssdevnet.Home"
android:label="#string/app_name" />
</application>
And this is what i used in style:
<style name="MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
</style>
and its still not working on Android 2.3.6 or below but working on 3 and above.
Also i tried to use this on the oncreate method on class file for that particular page:
requestWindowFeature(Window.FEATURE_NO_TITLE);// Removes title bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes notification bar
but its not working on my phone running Android 2.3.6 but its working on Emulator running Jellybean and i need something that works on all the versions.
And I need to know some things as i am a newbie to android:
Can we define a Global theme, and override that theme on some activities? if yes, what method can we use?
Or we have to define theme for every activity if we are targeting activities instead of app?
I also want to learn about deploying the custom themes in the app.. if there are some good tutorials and references please share.
Thanks in Advance!
Try using setTheme(..) before calling setContentView(...) and super.oncreate() and it should work fine in the Activity.
Check out the Android developer's site for more information.
I am simply trying to change the background color for an activity, however nothing has changed.
Here is the relevant XML:
styles.xml
<resources>
<style name="STBTheme" parent="android:Theme.Light" >
<item name="android:windowBackground">#color/blue</item>
</style>
</resources>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pedro.stb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/STBTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/STBTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Furthermore, I'm using Eclipse, and by changing the theme in the activity's xml, it does not change in the graphical layout.
Any help?
Edit
Got it to work. Have to clean the project before reloading the layout. Very annoying...
i had check your code its ok .
try <item name="android:Background">#ccff33</item>
instead of your <item name="android:windowBackground">#color/blue</item>.
and you have write android:theme="#style/STBTheme" > in application as well as activity also.
Just write in application tag .
Hope you will get your output now.
Open the preview of your activity and Click on the circled button as shown
Type the name of your custom theme and Click 'OK' as shown
In Manifest file add the attribute android:theme=".YourTheme" to the required Activity
You will have the theme of the current activity changed.
I dont know why Android Studio acts like it's drunk sometimes. I have two projects with same target,minimum SDK active. One of them had the splash screen theme implemented correctly, the other just wont show until I found this workaround.