So I know there are a ton of these questions, but every time I try what they say, my app does not seem to remove the title bar. I have done the style change:
<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="android:windowNoTitle">true</item> <!-- This should work but it does not -->
</style>
I have also tried:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide(); //This guy here
setContentView(R.layout.activity_title);
The above works but I still want to use the space the title bar takes for content in my app, which is why I want to be able to modify the XML code rather than use java. Any suggestions?
You can either:
<style name="noActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
and in your layout(at the root layout)
android:theme="#theme/noActionBar"
Or
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
However, the last one also hides the Statusbar. You can also set the theme to a default theme(look through the themes and find those with NoActionBar). The last one is useful if you have no plans to style the activity(for an instance if you use SurfaceView) with custom colors, etc.
For an instance you can change AppBaseTheme to have the parent Holo.Light.NoActionBar or any similar theme, but the name has to contain NoActionBar, othervise it has an actionbar
Add the below theme to style.xml:
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Then set this theme to your Activity in manifest:
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" />
Related
This is a simple app with a tag navigation. And I can't open it with getting a mistake.
A part of it is:
Caused by: 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 androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:572)
at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:159)
at com.example.tabexperiment.MainActivity.onCreate(MainActivity.java:29)
And here is a 28-th and 29-th lines in MainActivity(the message above says mistake is in 29-th line):
androidx.appcompat.widget.Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
I tried to cope with the problem but all what I found is that I should add this code in themes file:
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
and this line in Manifest:
android:theme="#style/Theme.TabExperiment"
So, I have that in my code but nothing is still working.
Help me, please.
you can use this:
<style name="NoActionBarTheme" parent="Theme.AppCompat.Light.NoActionBar">
<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>
OR
<activity android:name=".activity.YourActivity"
android:theme="#style/AppTheme.NoActionBar"/>
I have an activity (MainActivity.java) that is used as the launch screen while the main fragment is being loaded and other functionality takes place in background. This launch screen shows a brown tile background and an icon always. What I want is to show that backgound (in R.style.AppTheme_NoActionBar_LauncherNight) only when the variable dayMode is false (variable in Constants.java). Otherwise, the background should be the one in R.style.AppTheme_NoActionBar_LauncherDay (a white background and the same icon).
If I specify one or another background in the android:theme part of my Manifest, it is shown nicely. But what I want is to set one theme or another programmatically, depending on the value of dayMode, on the onCreate method of the activity. This is what is not working.
I tried using setTheme before calling super.onCreate or setContentView, as I read in other answers, but it is not working. I only find answers explaining the order in which you should call setTheme and setContentView, but they do not solve this problem.
My styles:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="autoCompleteTextViewStyle">#style/cursorColor</item>
<item name="android:textColorSecondary">#color/yellow_light</item>
</style>
<style name="AppTheme.NoActionBar.LauncherNight">
<item name="android:windowBackground">#drawable/launch_screen</item>
</style>
<style name="AppTheme.NoActionBar.LauncherDay">
<item name="android:windowBackground">#drawable/launch_screen_day</item>
</style>
My Manifest:
<activity
android:name="com.AlbaRam.myApp.MainActivity"
android:configChanges="keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar.LauncherNight"
android:launchMode="singleInstance"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
My ActivityMain:
#Override
protected void
onCreate(Bundle savedInstanceState) {
//This is not working
if (Constants.dayMode){
super.setTheme(R.style.AppTheme_NoActionBar_LauncherDay);
} else {
setTheme(R.style.AppTheme_NoActionBar_LauncherNight);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//rest of functionality
}
After some research I've discovered that this is not possible. Launch screens are used when we want to show something while our main functionality is loading, so we include the drawable we want to show in the Manifest to have this appearing fast while our main activity loads. This launch screen, as it is in the Manifest, appears before anything else, so if we could change the theme of the launch screen dinamically, we would lose that fast appearing while everything else loads.
Try this code
theme.xml
<resources>
<style name="AppThemeLight" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="android:windowAnimationStyle">#style/WindowAnimationTransition</item>
</style>
<style name="AppThemeDark" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="android:windowAnimationStyle">#style/WindowAnimationTransition</item>
</style>
<!-- This will set the fade in animation on all your activities by default -->
<style name="WindowAnimationTransition">
<item name="android:windowEnterAnimation">#android:anim/fade_in</item>
<item name="android:windowExitAnimation">#android:anim/fade_out</item>
</style>
activity
#Override
protected void onCreate(Bundle savedInstanceState) {
AppSettings settings = AppSettings.getInstance(this);
setTheme(settings.getBoolean(AppSettings.Key.USE_DARK_THEME) ? R.style.AppThemeDark : R.style.AppThemeLight);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transition_theme);
//
}
public void onCreate(Bundle savedInstanceState) {
if (Constants.dayMode){
setTheme(android.R.style.yourTheme);
} else {
setTheme(android.R.style.yourTheme);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.actvity);
}
I would like to change the color of my settings Tab located on the ActionBar, I have done very extensive research here and in other sources.
My Android version is 4.4.2.
My manifest is declared this way:
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
Basically I am doing what other sources showed me to:
<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light">
</style>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:panelFullBackground">#drawable/menu_background</item>
</style>
I also have replaced the android:panelFullBackground property for android:panelBackground, android:panelColorBackground and android:panelColorForeground switching from drawable resources to color values for each without results.
Finally I have also tried using ListPopupWindow parent variant:
<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light">
</style>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:panelFullBackground">#drawable/menu_background</item>
</style>
Here I have also switched the android:panelFullBackground property for android:panelColorBackground and android:popupBackground properties mixing them up with #android:color and #drawable resources too but is not working either.
Can you please tell me an effective way to configure this through the styles.xml file?
Thank you very much
Maybe you need to use Android Asset studio's ActionBarStyleGenerator to easily handle colors and not going through all the stuff. If you need more customizing on each Tab then you need to get a reference to actionbar using getActionBar()(or getSupportActionBar() in case of support actionbar) and create custom views Programmatically and add them to your actionbar using addTab(...)
I managed to find the right setting for my styles to accomplish the action bar settings custom color. This post helped as well: How to change the background color of Action Bar's Option Menu in Android 4.2?
The styles go this way:
File styles.xml:
<resources>
<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light">
</style>
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:itemTextAppearance">#style/TextAppearance</item>
</style>
<style name="MyActionBarTheme" parent="#android:Widget.Holo.Light.ActionBar">
<item name="android:background">#3892D3</item>
<item name="android:titleTextStyle">#style/MyActionBarTheme.Text</item>
</style>
<!--
This style reference did it, you can put a drawable resource or color resource reference there as well. For example: #drawable/menu_dropdown_image or #android:color/white
-->
<style name="PopupMenu" parent="#android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#3892D3</item>
</style>
<!---->
<style name="MyActionBarTheme.Text" parent="#android:TextAppearance">
<item name="android:textColor">#android:color/white</item>
<item name="android:textSize">20sp</item>
</style>
<style name="TextAppearance">
<item name="android:textColor">#android:color/white</item>
</style>
</resources>
Thank you!
I have different Activities in my App and in all of them I do not want the Action Bar. I cannot find how to disable it. I have tried to find an attribute to apply it to the main_activity.xml but so far I did not find anything. Can somebody help me please?
Haha, I have been stuck at that point a while ago as well, so I am glad I can help you out with a solution, that worked for me at least :)
What you want to do is define a new style within values/styles.xml so it looks like this
<resources>
<style name = "AppTheme" parent = "android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name = "NoActionBar" parent = "#android:style/Theme.Holo.Light">
<item name = "android:windowActionBar">false</item>
<item name = "android:windowNoTitle">true</item>
</style>
</resources>
Only the NoActionBar style is intresting for you. At last you have to set is as your application's theme in the AndroidManifest.xml so it looks like this
<application
android:allowBackup = "true"
android:icon = "#drawable/ic_launcher"
android:label = "#string/app_name"
android:theme = "#style/NoActionBar" <!--This is the important line-->
>
<activity
[...]
There are multiple ways of doing this.
1) Change the theme in Android Manifest
Below the Application element, you will find theme tag. Replace it with this one -
android:theme="#android:style/Theme.NoTitleBar"
If you are using AppCompat, use #android:style/Theme.AppCompat.NoActionBar.
This will set the theme for all activities. If you don't need the action bar in a specific acitivity, then set the theme in the activity container, ie
<activity android:theme="#android:style/Theme.NoTitleBar" ...>
You may also set android:theme="#android:style/Theme.NoTitleBar" theme in the styles and use it later on.
2) Create a Custom Theme
Add this in res/values/styles.xml
<style name="NoActionBar" parent="#android:style/Theme.Holo.Light">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
and then set it as your activity's theme in Manifest:
<activity android:theme="#style/NoActionBar" ... />
3) Dynamically Remove the Action Bar
Put this code in the onCreate method before setting content view -
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
If you are using the support library use getSupportActionBar().
If you're using AppCompat, declare your activity in AndroidManifest.xml as follows:
<activity
android:name=".SomeActivity"
...
android:theme="#style/Theme.AppCompat.Light.NoActionBar" />
Considering everyone is posting older ways of hiding the ActionBar here is the proper way of implementing it within styles for AppCompat support library. Which I highly suggest moving toward if you haven't already.
Simply removing the ActionBar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
If you are using the appcompat support libraries, this is the easiest and recommended way of hiding the ActionBar to make full screen or start implementing to toolbar within your layouts.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Your Toolbar Color-->
<item name="colorPrimary">#color/primary</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- colorAccent is used as the default value for colorControlActivated,
which is used to tint widgets -->
<item name="colorAccent">#color/accent</item>
<!-- You can also set colorControlNormal, colorControlActivated
colorControlHighlight, and colorSwitchThumbNormal. -->
</style>
Then to change your toolbar color
<android.support.v7.widget.Toolbar
android:id=”#+id/my_awesome_toolbar”
android:layout_height=”wrap_content”
android:layout_width=”match_parent”
android:minHeight=”?attr/actionBarSize”
android:background=”?attr/primary” />
Last note: Your Activity class should extend AppCompatActivity
public class MainActivity extends AppCompatActivity {
<!--Activity Items -->
}
Default style you getting in res/value/style.xml like
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
And just the below like in your activity tag,
android:theme="#style/AppTheme.NoActionBar"
If you want most of your activities to have an action bar you would probably inherit your base theme from the default one (this is automatically generated by Android Studio per default):
<!-- 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>
And then add a special theme for your bar-less activity:
<style name="AppTheme.NoTitle" parent="AppTheme">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="actionBarTheme">#null</item>
</style>
For me, setting actionBarTheme to #null was the solution.
Finally setup the activity in your manifest file:
<activity ... android:theme="#style/AppTheme.NoTitle" ... >
You may also change inheritance from ActionBarActivity to Activity as written here.
UPDATE
A good solution is here:
#Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
}
open Manifest and add attribute theme = "#style/Theme.AppCompat.Light.NoActionBar" to activity you want it without actionbar :
<application
...
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
...
</activity>
</application>
I will try to show it as simple as i can:
DECLARE FULL SCREEN ACTIVITY IN ANDROID MAINIFEST file:
<activity
android:name=".GameActivity"
android:label="#string/title_activity_game"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
Now in Android studio (if you using it) open your Activity xml file ( in my example activity_game.xml) in designer and select theme (above mobile phone in designer click button with small circle) and then select Mainfest Themes on the left side and then NoTitleBar.Fullscreen.
Hope it will help!
Please find the default theme in styles.xml
<!-- 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>
And change parent this way
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
android:theme="#style/Theme.MaterialComponents.Light.NoActionBar"
Using this theme worked for me
Put this line in your Activity in the Manifest:
<activity android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
...
</activity>
and make sure you didn't put Toolbar in your layout
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
/>
Create an new Style with any name, in my case "Theme.Alert.NoActionBar"
<style name="Theme.Alert.NoActionBar" parent="Theme.AppCompat.Dialog">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
set its parent as "Theme.AppCompat.Dialog" like in the above code
open AndoridManifest.xml and customize the activity you want to show as Alert Dialog like this
<activity
android:excludeFromRecents="true"
android:theme="#style/Theme.Alert.NoActionBar"
android:name=".activities.UserLoginActivity" />
in my app i want show my user login activity as Alert Dialog, these are the codes i used. hope this works for you!!!
It's Really Simple Just go to your styles.xml change the parent Theme to either
Theme.AppCompat.Light.NoActionBar or Theme.AppCompat.NoActionbar and you are done.. :)
I know I can change activity transition using the following code right after startActivity() or finish()
activity.overridePendingTransition(R.anim.activity_close_enter, R.anim.activity_close_exit);
But if I have ten activities in my app, I have to do that ten times; and it is quite hard to modify. So I'm wondering if there is a way to set transition for all activities within the application at once. Is there any corresponding configuration in AndroidManifest.xml?
Thanks!
You want to first create a <style> in res/styles.xml, like this:
<style name="YourAnimation.Activity" parent="#android:style/Animation.Activity">
<item name="android:windowEnterAnimation">#anim/your_in_down</item>
<item name="android:windowExitAnimation">#anim/your_out_down</item>
</style>
Then you can apply the style to a theme, in the same file:
<style name="YourTheme" parent="android:Theme.Translucent">
...
<item name="android:windowAnimationStyle">#style/YourAnimation.Activity</item>
</style>
And finally apply the theme to your activities in the manifest:
<activity
android:name=".YourActivity"
android:theme="#style/YourTheme" />
Look at these links for reference:
Android Reference - Apply A Theme
Android Reference - WindowEnterAnimation
I know this has been answered but here is what I did in mine. We still support API 14 so there are some animations missing that I had to pull into the project from API 22( slide_in_right, slide_out_left). What this does is to slide in the screens when you open a new activity and slides the closing one out to the left. When you press back it will then do the opposite, sliding from the left the previous screen and closing out to the right the current screen.
<style name="YourTheme" parent="android:Theme.Translucent">
...
<item name="android:windowAnimationStyle">#style/YourAnimation.Activity</item>
</style>
<style name="YourAnimation.Activity" parent="#android:style/Animation.Activity">
<item name="android:activityOpenEnterAnimation">#anim/slide_in_right</item>
<item name="android:activityOpenExitAnimation">#anim/slide_out_left</item>
<item name="android:activityCloseEnterAnimation">#android:anim/slide_in_left</item>
<item name="android:activityCloseExitAnimation">#android:anim/slide_out_right</item>
</style>
Step 1: Create one base activity
Step 2: Extend all your activity to this base activity
Step 3: In your base activity add following code
#Override
protected void onStart() {
super.onStart();
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
#Override
protected void onPause() {
super.onPause();
if (isFinishing()) {
overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
}
}
My solution is mostly like of others...
<style name="YourAnimation.Activity" parent="#android:style/Animation.Activity">
<item name="android:windowEnterAnimation">#anim/slidefromright</item>
<item name="android:windowExitAnimation">#anim/slidetoright</item>
</style>
<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="android:windowAnimationStyle">#style/YourAnimation.Activity </item>
</style>
</resources>