How to remove two toolbars from a fragment?
((AppCompatActivity)getActivity()).getSupportActionBar().hide();
even after using this command the second blank toolbar remains and the top toolbar disappears.
Use NoActioonBar Theme instead of Default one in Manifest file
<activity .....
android:theme="#style/Theme.AppCompat.NoActionBar"
/>
add no action bar line in manifest
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" />
then add in your styles.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Related
I need that the sentence in the mainActivity "datos tarjeta credito" appears also in the top of the second activity. The xml layouts are the same, I don't understand where can I change this. This is what is now:
I tried to attach the xml layouts, but its not working.
If you are using Activity with Actionbar enabled theme, then you can use below code to change the title of actionbar in all activity programatically.
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle("Your Title here");
}
Or you can set the title in manifest itself by:
<activity
android:name="your activity name"
android:label="Your Title Here"/>
In your Activity theme put that:
(I used Theme.AppCompat.Light.DarkActionBar as an example, but anyone should do)
<style name="yourTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">true</item>
<item name="windowNoTitle">true</item>
</style>
<application
...
android:theme="#style/yourTheme"> <!-- apply to all activities ->
<activity
android:name=".MainActivity"
android:theme="#style/yourTheme"> <!-- apply to one activity ->
</activity>
</application>
I'm creating a music application when designing kits, I think I need to create a full screen activity I have tried
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
But that's not what I want, I want full screen but still retain notification bar
How to do this?
Thank!
In your theme:
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
In your activity onCreate:
Window window = getWindow();
WindowManager.LayoutParams winParams = window.getAttributes();
winParams.flags &= ~WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
window.setAttributes(winParams);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
Remove getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); this line from your code and just put change int your activity style.
<style name="LoginTheme" 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>
Manifest.xml
<activity android:name=".Login"
android:theme="#style/LoginTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Put this code above setContentView()
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
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've developed a simple demo application with a splash screen a map and some regular screens.
I have an action bar at the top that contains a logo. It all looks fine on my phone (Galaxy s1 I9000 V2.3) but when i test it on Galaxy s2 v4 the action bar appears also in the splash screen and in the map screen.
The spalsh and map activity are not even inheriting from ActionBarActivity so how is that possible and how can i make it go away?
Manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:theme="#style/Theme.AppCompat.Light" >
<activity
android:name=".HomeActivity"
android:icon="#drawable/android_logo"
android:label=""
android:logo="#drawable/android_logo" >
<!--
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
-->
</activity>
<activity
android:name=".MapActivity"
android:label="" >
</activity>
<activity
android:name=".PackageActivity"
android:icon="#drawable/android_logo"
android:label=""
android:logo="#drawable/android_logo" >
</activity>
<activity
android:name=".SplashActivity"
android:label="" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
MapActivity definition (it's a long one so i included just the definition):
public class MapActivity extends FragmentActivity implements LocationListener
Splash Activity:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
public class SplashActivity extends Activity{
private static final long SPLASH_DISPLAY_LENGTH = 2000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
Intent mainIntent = new Intent(SplashActivity.this,HomeActivity.class);
SplashActivity.this.startActivity(mainIntent);
SplashActivity.this.finish();
}
}, SPLASH_DISPLAY_LENGTH);
}
}
As you are asking about how to hide in a certain activity, this is what you need :
getSupportActionBar().hide();
Apply the following in your Theme for the Activity in AndroidManifest.xml:
<activity android:name=".Activity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
1.Go to your manifest.xml file.
2.Find the activity tag for which you want to hide your ActionBar and then add ,
android:theme="#style/Theme.AppCompat.NoActionBar"
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.NoActionBar"
>
If you want to get full screen without actionBar and Title.
Add it in style.xml
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
and use the style at activity of manifest.xml.
<activity ....
android:theme="#style/AppTheme.NoActionBar" > ......
</activity>
The ActionBar usually exists along Fragments so from the Activity you can hide it
getActionBar().hide();
getActionBar().show();
and from the Fragment you can do it
getActivity().getActionBar().hide();
getActivity().getActionBar().show();
This works for me! Put this in your Activity in manifests
<activity
// ...
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
// ...
</activity>
You can also make your custom theme in styles.xml like this:
<style name="Theme.MyCustomTheme" parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name = "android:windowActionBar">false</item>
<item name = "android:windowNoTitle">true</item>
// more custom...
</style>
Hope this help.
If you were using Theme.AppCompat.Light, a better equivalent would be Theme.AppCompat.Light.NoActionBar.
I found that using Theme.AppCompat.NoTitleBar caused my button text to be invisible so I am using Theme.AppCompat.Light.NoActionBar.
<activity android:name=".Activity"
android:label="#string/app_name"
android:theme="#android:style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
To hide the ActionBar add this code into java file.
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
You can use Low Profile mode
See here
Just search for SYSTEM_UI_FLAG_LOW_PROFILE that also dims the navigation buttons if they are present of screen.
Apply the following in your Theme for the Activity in AndroidManifest.xml:
<activity android:name=".DashboardActivity"
android:theme="#style/AppFullScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Then Apply the following in your Style in style.xml
<style name="AppFullScreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
The above answers would help with the ActionBar thing. To add to it, use the following code in case you are using the Splash Screen:
Use this before you set the content view:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Just to clarify, here's how you do it:
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
This would make your screen a full screen, i.e remove the top bar where you see the network bar, etc
#Override
public void onResume() {
super.onResume();
getSupportActionBar().hide();
}
#Override
public void onStop() {
super.onStop();
getSupportActionBar().show();
}
For selectively hiding Actionbar in activities:
Add the following code to onCreate (preferably on the last line of the function)
Kotlin:
supportActionBar?.hide()
Java:
getSupportActionBar().hide();
This works in API 27
In the styles.xml replace code to the following....
<resources>
<!-- No Action Bar -->
<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>
</resources>
Then in the files (eg. activity_list.xml) in which you do want to have a toolbar put the following code.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/colorPrimary"/>
If you have problems switch to linear layout (because that is what this code is tested on)
From here:
Beginning with Android 3.0 (API level 11), all activities that use the default theme have an ActionBar as an app bar. However, app bar features have gradually been added to the native ActionBar over various Android releases. As a result, the native ActionBar behaves differently depending on what version of the Android system a device may be using. By contrast, the most recent features are added to the support library's version of Toolbar, and they are available on any device that can use the support library.
So one option is to disable ActionBar completely (in the app manifest.xml file) and then add Toolbar in every page that needs an ActionBar.
(follow the above link for step-by-step explanation)
Add New Style in your style.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>
<style name="LoginTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
and then add following line in your manifest
<activity android:name=".Login"
android:label="#string/app_name"
android:theme="#style/LoginTheme"
>
If you activity extends AppCompatActivity then you can add this line
super.getSupportActionBar().hide(); before setContentView()
Replace AndroidManifest.xml
android:theme="#style/FullscreenTheme"
to
android:theme="#style/Theme.Design.NoActionBar"
Check for padding attribute if the issue still exists after changing theme.
Padding Issue creating a white space on top of fragment window / app window
Once you remove the padding - top value automatically the white space is removed.
First cheek MainActivity for activity tag,Like -
public class MainActivity extends AppCompatActivity
Then goto menifest xml file and write-
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
in activity tag
I've searched SO but not found similar questions as I'm not sure how to phase it in a sentence. I am using ActionBarSherlock, with a logo instead of the launcher icon (i.e. 72x72 icon) with text in the top corner of the activity.
When the activity loads for the first time, for a fraction of a second. I see the launcher icon and label defined in the manifest (as below), before the action bar appears with the logo. This home activity is very simple, so its not doing any additional loading which could cause a delay.
<application
android:hardwareAccelerated="true"
android:icon="#drawable/launcher_icon"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<activity
android:name=".SplashScreenActivity"
android:label="#string/app_name"
android:logo="#drawable/ab_logo"
android:theme="#android:style/Theme.Light.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeActivity"
android:label="#string/homeitle"
android:logo="#drawable/ab_logo"
android:theme="#style/MyTheme" >
</activity>
</application>
I can make the text "disappear" by styling it to be the same colour as the background, but i cant find a way to remove/hide the launcher icon from the activity.
I have setup a splashscreen activity (as in manifest above), which just loads my home activity where the issue occurs. This does help, but sometimes the issue still occurs when loading the activity.
public class SplashScreenActivity extends Activity
{
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
#Override
public void onResume()
{
super.onResume();
Intent i = new Intent(getBaseContext(), HomeActivity.class);
startActivity(i);
finish();
}
}
Does anyone know of a way to hide the launcher icon & title label, so that it doesn't show up prior to ActionBarSherlock being displayed? Ideally so a splash screen is not needed, as there are several ways to access the activity which would avoid the splashscreen shown above.
--- Update My Theme File ----
<style name="MyTheme" parent="Theme.Sherlock.ForceOverflow">
<item name="android:windowBackground">#color/white</item>
<item name="android:actionBarStyle">#style/MyTheme.ActionBar</item>
<item name="android:actionMenuTextColor">#color/white</item>
<item name="actionBarStyle">#style/MyTheme.ActionBar</item>
<item name="actionMenuTextColor">#color/white</item>
</style>
<style name="MyTheme.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/blue</item>
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="android:displayOptions">showHome|useLogo</item>
<item name="displayOptions">showHome|useLogo</item>
<item name="background">#color/blue</item>
<item name="titleTextStyle"> #style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/blue</item>
</style>
Fixed it by adding icon to the style, which is the same as the logo. This overrides the launcher icon.
<style name="MyTheme.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/infostop_blue</item>
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="android:displayOptions">showHome|useLogo</item>
<item name="displayOptions">showHome|useLogo</item>
<item name="android:icon">#drawable/ab_logo</item>
<item name="icon">#drawable/ab_logo</item>
<item name="background">#color/blue</item>
<item name="titleTextStyle"> #style/MyTheme.ActionBar.TitleTextStyle</item>
</style>