I want to disable ActionBar shadow but only in one Activity. If I use this code it will be change in whole aplication.
<style name="MyAppTheme" parent="android:Theme.Holo.Light">
<item name="android:windowContentOverlay">#null</item>
</style>
I tried this code, but it is not working
getSupportActionBar().setElevation(0);
Any suggestion...?
You can set your own style for Activity for this:
<!-- Your main theme with ActionBar shadow. -->
<style name="MyAppTheme" parent="android:Theme.Holo.Light">
....
</style>
<!-- Theme without ActionBar shadow (inherits main theme) -->
<style name="MyNoActionBarShadowTheme" parent="MyAppTheme">
<item name="windowContentOverlay">#null</item>
<item name="android:windowContentOverlay">#null</item>
</style>
So in Manifest.xml you can set different style for all Activities:
<!-- Activity with ActionBar shadow -->
<activity
android:name=".ShadowActivity"
android:theme="#style/MyAppTheme"/>
<!-- Activity without ActionBar shadow -->
<activity
android:name=".NoShadowActivity"
android:theme="#style/MyNoActionBarShadowTheme"/>
Or you can set the right theme programmatically in onCreate() method:
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.MyNoActionBarShadowTheme);
super.onCreate(savedInstanceState);
//...
}
Add app:elevation="0dp" to appbarlayout as shown below:
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/home_tool_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
Create a new Theme that inherits your App theme:
<style name="MyAppTheme.NoShadow" parent="MyAppTheme">
<item name="android:windowContentOverlay">#null</item>
</style>
and let your activity use this theme. In your Manifest:
<activity
android:name="...MyShadowlessActivity"
android:theme="#style/MyAppTheme.NoShadow" .../>
Related
There are questions answered on this, however, they don't seem to work with the new AndroidX
My Main Activity is saying "Home" in the toolbar, when I want it to say something else. I'm only using the default navigation drawer activity from Android Studio
Here's my Main Activity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Let's say I want to set the text of the toolbar as something, how do I do it?
Here's the styles.xml too for reference
<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>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Depending on your requirements, you could statically change it by using:
getSupportActionBar().setTitle("Some Title Here");
There are couple of ways to do that, as i am using Material Design Dependency i change my AppTheme from resources to this
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.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>
Specifically this is the tag i am talking about
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar>
EDIT: In case if you want Material Design Dependency , here it is:
// New Material Design
implementation 'com.google.android.material:material:1.0.0'
Then go to your particular activity's XML and add custom toolbar, like so:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"/>
</LinearLayout>
Notice, here i have used Linear Layout just not to mess with constraints..
Then into your activity, do this:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)// this is your toolbar ID
setTitle("Hello World") // your toolbar title
}
ThankYou!
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar>
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"android.support.v7.widget.Toolbar
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary"
android:text="<your text>">
</androidx.appcompat.widget.Toolbar>
I am using an activity to work as a dialog box. However, the actionBar on the dialog activity is not disappearing. I have tried using:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_dialog);
}
It Doesn't work. I also set the theme of the app (from the manifest) to be as following:
<activity
android:name=".DialogActivity"
android:label="#string/title_activity_dialog"
android:theme="#style/Theme.AppCompat.Light.Dialog.Alert" >
</activity>
Following is the Screen shot is of what I am getting and I am aiming to remove this pointless white bar which is hiding the text.
The Screen Shot of the Emulator
Thank you.
Create custom theme eg. CustomTheme in styles.xml
<style name="CustomTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
</style>
and in manifest.xml use
android:theme="#style/CustomTheme"
Try this:
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
<item name="windowNoTitle">true</item>
Although in theory customizing the theme with no title bar should work, however in my case it didn't work. So I solved it by removing the following section from the activity_class.xml
<android.support.v7.widget.Toolbar android:id="#+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
I'm trying to customize the style of my application inside the SettingsActivity. I would like to change the status bar and toolbar colors, and if possible also the window background(from dark to light grey) and text colors(change white for black for example).I've read many websites and I've tried different options in the style.xml but with no success. In SettingsTheme colorPrimary and colorPrimaryDark doesn override the default color of the parenttheme. Thanks in advance.
This is the main activity of my app
and this is the settings activity i have now
style.xml
<resources>
<!-- application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#3F51B5</item>
<item name="colorPrimaryDark">#1A237E</item>
<item name="colorAccent">#FFEB3B</item>
<item name="android:windowBackground">#color/custom_background_light_grey</item>
<item name="dropDownListViewStyle">#style/PopupMenuListView</item>
</style>
<style name="PopupMenuListView" parent="#style/Widget.AppCompat.Light.ListView.DropDown">
<item name="android:divider">#FF0000</item>
<item name="android:dividerHeight">2dp</item>
<item name="android:background">#3F51B5</item>
</style>
<style name="SettingsTheme" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="colorPrimary">#3F51B5</item>
<item name="colorPrimaryDark">#1A237E</item>
</style>
</resources>
toolbar in xml
<android.support.v7.widget.Toolbar
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary">
</android.support.v7.widget.Toolbar>
Are you sure you use the Toolbar in settings? And may be you forgot to add "NoActionBar Theme" in Setting Activity?
(I know this may not be the answer but I couldn't comment because of the reputation.)
Please replace above code in your Settings activity toolbar code.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
I am trying to implement a Light Theme of AppCompat with a dark toolbar (action bar), however when adding the toolbar dynamically or using <include /> the text fails to display in the correct color (black instead of white). The default action bar is styled correctly, but when I add the toolbar it is not.
Here is my code:
toolbar.xml
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
app:theme="#style/AppTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:navigationContentDescription="#string/abc_action_bar_up_description"
android:background="?attr/colorPrimary"
app:navigationIcon="?attr/homeAsUpIndicator"
app:title="#string/action_settings"
/>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#ff299725</item>
<item name="colorPrimaryDark">#ff1d691b</item>
<item name="colorAccent">#ff5fb10b</item>
</style>
</resources>
However I get this in preview and live environment:
I have tried different versions of AppCompat (v.22.1, v.22.2, v.21.0.3) all replicate the issue, I have tried adding extra styles for textColor and all that happens is that it styles everything white.
Any help SO legends?
In your toolbar.xml, remove the app:theme attribute and use this instead:
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
Also, depending on how you're implementing toolbar, you may want to change your base theme (in styles.xml) to use the NoActionBar variant, like so:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
styles.xml
<style name="Toolbar" parent="#style/ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">#color/xxx</item>
<item name="android:background">#color/xxx</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="#style/Widget.AppCompat.DrawerArrowToggle">
<item name="color">#color/xxx</item>
<item name="gapBetweenBars">4dp</item>
</style>
my_toolbar.xml
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/Toolbar"
/>
The Google Maps application has a transparent ActionBar, through which the map is visible.
I am able to set the transparency of the ActionBar using this:
<style name="Theme.MyTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#64000000</item>
</style>
But how can I show my ImageView behind the ActionBar?
You can enable overlay mode of the ActionBar. To do it you have to set (android:)windowActionBarOverlay item in the theme to true.
<style name="MyTheme" parent="Theme.Sherlock">
...
<item name="windowActionBarOverlay">true</item> <!-- for ActionBarSherlock -->
<item name="android:windowActionBarOverlay">true</item>
</style>
You can also set it at run-time:
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
This will the ActionBar a semi-transparent floating bar.
Like any requestWindowFeature..., this should be called before adding content.
After the setContentView, you can then set a background from your Drawable with this:
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg));
Change getActionBar with getSupportActionBar for ActionBarSherlock
actionbar_bg.xml with the root element of shape:
<solid android:color="#64000000" />
Although I find Tomik's solution great, this will be useful for those one-off cases for a few activities rather than an across the board style.
If someone needs the transparent bar but only for certain activities while using a solid one in the rest of them, it might be worth creating two different styles and using the manifest to get control over it:
<style name="MyThemeOverlay" parent="Theme.Sherlock">
...
<item name="windowActionBarOverlay">true</item> <!-- for ActionBarSherlock -->
<item name="android:windowActionBarOverlay">true</item>
<!-- any stuff common here, colours, etc -->
<!-- define the style for native ActionBar for Android 4 and higher -->
<item name="android:actionBarStyle">#style/myActionbarTransparent</item>
<!-- define the style for ActionBarSherlock -->
<item name="actionBarStyle">#style/myActionbarTransparent</item>
</style>
<style name="MyThemeNoOverlay" parent="MyTheme">
<item name="windowActionBarOverlay">false</item> <!-- for ActionBarSherlock -->
<item name="android:windowActionBarOverlay">false</item>
<!-- any stuff specific for no overlay activity action bars -->
<!-- define the style for native ActionBar for Android 4 and higher -->
<item name="android:actionBarStyle">#style/myActionbar</item>
<!-- define the style for ActionBarSherlock -->
<item name="actionBarStyle">#style/myActionbar</item>
</style>
<style name="myActionbar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#color/white</item>
</style>
<style name="myActionbarTransparent" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#color/transparent</item>
</style>
and then in your AndroidManifest.xml you can either use one of them as default and the other one for some specific activities by doing something like:
<application
...
android:theme="#style/MyThemeOverlay">
...
<activity
android:name=".Activity1"
/>
<activity
android:name=".Activity2"
android:theme="#style/MyThemeNoOverlay"
/>
<activity
android:name=".Activity3"
/>
<activity
android:name=".Activity4"
android:theme="#style/MyThemeNoOverlay"
/>
...
in styles.xml:
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="colorPrimary">#color/semiTransparent5</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" >
<item name="windowActionBarOverlay">true</item>
</style>
in activity_main.xml:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="#layout/content_main" />