How can I remove android actionbar Shadow - android

I'm using Android Studio for programming. Target SDK is 23 and Minimum SDK is 15
I'm trying to remove the shadow between my actionbar and my sliding tab layout. But I'm not able to.
Note : The shadow is only visible in Android 5 and upper.
I have used <item name="elevation">0dp</item> and getSupportActionBar().setElevation(0);
But still it doesn't work...
My Style.xml
<resources>
<!-- Base application theme. -->
<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>
</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">
<item name="elevation">0dp</item>
</style>
My Style V21
<resources>>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
</style>
My MainActivity.java onCreateCode:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setElevation(0);
....

You're missing the prefix in your style.
<item name="android:elevation">0dp</item>
That said you could also set it directly on your AppBarLayout
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:elevation="0dp"
android:theme="#style/AppTheme.AppBarOverlay">
Or what I like to do is move the SlidingTabLayout into the AppBarLayout so the shadow appears below it:
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="#style/AppTheme.AppBarOverlay">
<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"
/>
<com.ccswe.SmokingLog.views.widgets.SlidingTabLayout
android:id="#+id/sliding_tabs"
android:layout_width="wrap_content"
android:layout_height="#dimen/tab_layout_height"
/>
</android.support.design.widget.AppBarLayout>

Try adding setting the elevation to 0 with the help of the support library
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
android:theme="#style/AppTheme.AppBarOverlay">

Related

Change color and size of the title in Toolbar- Android

I am trying to change the title color and size of the toolbar but nothing happens. I search everywhere and nothing seems to work. I am using minsdk 19 api. Here is my code:
**activity.main.xml**
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
>
<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>
**style.xml**
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryDarkColor</item>
<!--<item name="colorAccent">#color/primaryLightColor</item>-->
<item name="android:textColor">#color/primaryTextColor</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">
<item name="actionBarStyle">#style/MyTitleTextStyle</item>
</style>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="MyTitleTextStyle" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textColor">#color/primaryColor</item>
</style>
</resources>
It's well explained here. Add this to your Toolbar:
app:titleTextAppearance="#style/Toolbar.TitleText"
And create a style for it:
<style name="Toolbar.TitleText" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textColor">#FFFFFF</item>
</style>
You can also try this. This will allow you to control textsize
Define ActionBarTextAppearance in style.xml
<style name="ActionBarTextAppearance" parent="#android:style/TextAppearance.Medium">
<item name="android:textSize">30sp</item>
<item name="android:textColor">#ec1212</item>
<item name="android:textStyle">bold</item>
</style>
Then use in main.xml
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:titleTextAppearance="#style/ActionBarTextAppearance"
/>
The easy way to achive tour goal is to have Textview as title inside your Toolbar and then give your choice size and color
<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"
>
<Textview
android:layout_width="wrap_parent"
android:layout_height="wrap_parent"/>
</android.support.v7.widget.Toolbar>

How to set Toolbar text and hamburger icon to be white?

Toolbar text and hamburger icon is in black color and I want in white color.
I have tried this, this and this solution but nothing worked.
Source code link: https://github.com/vaibhavsingh97/Solucion/tree/master/Android%20Basic%20Nanodegree/Project%206/TourGuide
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>
<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">
<item name="android:textColorPrimary">#color/white</item>
<item name="android:textColorSecondary">#color/white</item>
</style>
</resources>
app_bar_main.xml
<android.support.design.widget.AppBarLayout
style="#style/AppTheme.AppBarOverlay"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_home" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="#drawable/ic_play"/>
</android.support.design.widget.CoordinatorLayout>
Android Studio: 3.0 Canary 9
SDK used for build: 26
Inside Activity, you can use
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitleTextColor(getResources().getColor(R.color.white));
If you love to choose xml for both title color & back arrow white just add this style in style.xml .
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:textColorSecondary">#android:color/white</item>
<item name="actionMenuTextColor">#android:color/white</item>
</style>
And toolbar look like :
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
app:theme="#style/ToolBarStyle"
android:layout_height="?attr/actionBarSize"
/>
UPDATE
try this
<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
</style>
<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="#style/Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/black</item>
</style>
So check <item name="color">#android:color/black</item> line. Just change your desired color here.
try darkActionBar theme as toolbar style in XML file

change actionbar style in android

I want to override appcompat action bar style, I do this:
<style name="AppTheme" 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="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:background">#android:color/black</item>
but this doesn't apply to the element,
this is an XML element:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
/>
Your help will be appreciated, Thank you
use local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
for more details refer https://dzone.com/articles/getting-started-with-android-app-and-material-desi
Set Activity theme to this style
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
In your xml your toolbar should be created in AppBarLayout
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/MyTheme"
app:elevation="0dp"
app:popupTheme="#style/AppTheme.PopupOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="#style/MyTheme"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
MyTheme should have parent ThemeOverlay.AppCompat.Dark.ActionBar
<style name="MyTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
//customize toolbar here`</style>
`
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

Android Studio - Transparent Action Bar - Navigation Drawer

I have a navigation drawer template. I have modified the action bar so I don't see the title. And I know how to change the colors, but I do not know how to get this effect:
This is my current status:
This is my styles.xml (what teme I'm using):
<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" />
You can use Toolbar with transparent background.
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/your_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#4BAE4F"
android:orientation="vertical">
<!--Place your content here-->
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/transparent"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
</android.support.v7.widget.Toolbar>
</RelativeLayout>
MainActivity.java:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
}
}
styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
From API 19 you can set parameter <item name="android:windowTranslucentStatus">true</item> in your styles.xml to make status bar transparent as well.

Toolbar Android 4.0 - 5.0

Is There a way to make compatible toolbar in 4.0 and 5.0 android app?
I'm developing an android app and my activity extends AppCompatActivity and I'm using 'com.android.support:appcompat-v7:23.2.0', but in 4.0 versione toolbar doesn't show and actionbar is null.
I do not know how to fix without totally changing the code.
this is my toolbar code xml:
<android.support.design.widget.AppBarLayout
xmlns:compat="http://schemas.android.com/apk/res-auto"
compat:showAsAction="always"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:titleTextColor="#color/maroon"
android:textColorPrimary="#color/maroon"
android:textColorSecondary="#color/maroon"
android:actionMenuTextColor="#color/maroon"
app:popupTheme="#style/AppTheme.PopupOverlay"
app:theme="#style/ToolBarStyle"/>
</android.support.design.widget.AppBarLayout>
..activity code:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
....style code:
<!-- ToolBar -->
<style name="ToolBarStyle" parent="Theme.AppCompat">
<item name="android:textColorPrimary">#color/maroon</item>
<item name="android:textColorSecondary">#color/maroon</item>
<item name="actionMenuTextColor">#color/maroon</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:background">#color/tw__solid_white</item>
</style>
<style name="AppTheme_noAction" parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowActionBarOverlay">false</item>
<item name="windowNoTitle">true</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
Thanks.

Categories

Resources