Hide or remove Action Bar on specific Activity | Android - java

How I can remove Action Bar on specific activity not for all application, for example I have Sign Up activity and for this activity I want to remove Action Bar

In your AndroidManifest.xml use NoActionBar theme for your Activity like this:
<activity android:name=".SignUpActivity"
android:theme="#style/AppTheme.NoActionBar"/>
and in your styles.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

from within your activity:
getActionBar().hide();
or
getSupportActionBar().hide();
I would suggest to migrate to ToolBar, new Android API for the same purpose. The main benefit of ToolBar is that you can treat it like other views, it guarantees to you a more flexible approach.

<!-- 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>

If you have an ActionBar, you can use getActionBar().hide();
If you have a SupportActionBar, you can use getSupportActionBar().hide();

Remove Action Bar on specific Activity go to Activity java file here your Activity class extends with AppCompatActivity remove the AppCompatActivity and extends with Activity and go to xml file and select Theme NoTitleBar or go to Manifests file select your Activity and add Theme on your Activity android:theme="#android:style/Theme.NoTitleBar"/>

For kotlin you can use supportActionBar?.hide()

Related

Removing Title Bar on Android App

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" />

FullScreen Layout doesn't work on Android

I have an activity_login.xml with a FrameLayout in Android Studio, which doesn't appear in fullscreen mode with this configuration:
AndroidManifest.xml:
<activity
android:name=".Activities.LoginActivity"
android:label="#string/title_activity_login"
android:launchMode="singleTop"
android:theme="#style/LoginScreenTheme.TranslucentBar" >
</activity>
Styles.xml:
<style name="LoginScreenTheme.TranslucentBar" parent="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
The Toolbar is still appearing in the Layout.
Look at your activity Layout, most likely there is Toolbar view that AndroidStudio generated for you. If that does not work add to the style:
<item name="android:windowFullscreen">true</item>
Modify onCreateView() as below
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
In order to remove the Toolbar/ActionBar you don't need to do anything special at all. Just keep everything as default and go to the styles.xml and change the AppTheme to Theme.AppCompat.Light.NoActionBar and also make sure that your activity extends AppCompactActivity. It always works for me. Hope it will help you as well. And if you also wants to remove the StatusBar then follow #EKN solution above ;)
I don't do anything and today when I started my project, the activity was in fullscreen.

How to remove the menu from an action bar (java)

I'm new to android development and wanted to make a tabbed application, so I started with google's file form the documentation and I would like to remove the most above part of the action bar (where the logo and the app name stands). I've tried styling it like this:
<resources>
<style name="ThemeHoloWithActionBar" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="android:actionBarSize">50dip</item>
</style>
<style name="ActionBarTabStyle" parent="#android:style/Widget.Holo.ActionBar.TabView">
<item name="android:minHeight">50dip</item>
</style>
hoping that it would push the size of the other bar to 0 but it didn't work.
Edit:
when using:
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
I Can't get the error formatted correctly so I uploaded an image :
http://i.imgur.com/ED7InpD.jpg
If you don’t need the action bar, you can remove it from your entire app or from individual activities. This is appropriate for apps that never used the options menu or for apps in which the action bar doesn’t meet design needs (such as games). You can remove the action bar using a theme such as Theme.Holo.NoActionBar or Theme.DeviceDefault.NoActionBar.
in style.xml add this:
<resources>
<style name="NoActionBar" parent="#android:style/Theme.Holo.NoActionBar">
<!-- Your style here -->
</style>
</resources>
in AndroidManifest.xml add this:
<!-- [...] -->
<application android:name="#style/NoActionBar"
<!-- [...] -->
or try with this:
<!-- [...] -->
<application android:theme="#style/NoActionBar">
<!-- [...] -->
To remove actionbar, you need add:
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
to your AppTheme style file, after remove, then you can not use default actionbar to add tabs.
If you still want to use tabs, then you have to use SlidingTabLayout to make a custom ViewPager title strip. There is Android sample project SlidingTabsBasic, which show detail how to make custom tabs.

Android Activity without ActionBar

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.. :)

How to change all the activity transitions at once in Android application?

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>

Categories

Resources