Android no Action Bar Shadown API Level 21 - android

Recently I noticed that the shadow of my action bar had disappeared, and when looking into it it appears that on KitKat devices the shadow is present but on Lollipop+ it remains non-existant. I feel it is as though something that I am missing from the docs and if someone could point me in the right direction it would be very helpful. Thank you in advance!
This is my styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="GenericTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/GenericActionBar</item>
<item name="android:actionBarStyle">#style/GenericActionBar</item>
<item name="android:windowActionBar">true</item>
<item name="windowActionBar">true</item>
</style>
<!-- ActionBar styles -->
<style name="GenericActionBar"
parent="Widget.AppCompat.ActionBar">
<item name="background">#android:color/holo_blue_bright</item>
<item name="android:background">#android:color/holo_blue_bright</item>
</style>
</resources>
Edit : No I am not using a tool bar

If you want shadow in your Toolbar in API 21+ you have to add one XML attribute in the toolbar like this :
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/tab_primary_color"
android:elevation="8dp"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>

Related

Make Tool Bar Transparant in Frgament

I want to make Toolbar as transparent in fragment,
I have attached Image here,Here I cant able to see full image,
Can I get help from some one to resolve this issue?
add new style
<style name="CustomActionBar" parent="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
set into toolbar
<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="wrap_content"
app:theme="#style/CustomActionBar"/>

Support Action Bar not applying my style?

I've been spending hours trying to fix the changing action bar title size according to this stack overflow post:
Android Toolbar: small title text in landscape mode
Unfortunately, it seems that no matter what I do, anything regarding the actionbar style won't actually apply.
My styles v14 file:
<!-- Main theme -->
<style name="MyTheme" parent="Theme.AppCompat">
<item name="android:actionBarItemBackground">#drawable/selectable_background</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.MyTheme</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.MyTheme</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.MyTheme</item>
<item name="android:spinnerItemStyle">#style/Widget.MyTheme.TextView.SpinnerItem</item>
<item name="android:spinnerDropDownItemStyle">#style/Widget.MyTheme.DropDownItem</item>
</style>
My ActionBar styles:
<style name="Widget.MyTheme.ActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#drawable/ab_solid</item>
<item name="android:titleTextStyle">#style/my_title_style</item>
</style>
<style name="my_title_style" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="textSize">20sp</item>
</style>
And, of course, "MyTheme" is applied in the manifest as well - I've even tried adding it to all the individual activities as well, to no avail.
It seems that no matter what I do, stuff just won't apply. I've tried removing the android: namespace, I've tried using titleTextAppearance instead of titleTextStyle, I've basically emulated exactly how the parent themes do it, but it won't change anything. Anybody have a clue as to what's going on? I just recently updated to AppCompat so I'm not totally familiar with how everything works.
You need to use
<item name="background">#drawable/ab_solid</item>
<item name="titleTextStyle">#style/my_title_style</item>
for support library compatibility into your style.
Read Styling the Action Bar, section "For Android 2.1 and higher". Where it is given that you need to use two entries like
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
So your complete style would be
<style name="Widget.MyTheme.ActionBar" parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="android:background">#drawable/ab_solid</item>
<item name="android:titleTextStyle">#style/my_title_style</item>
<item name="background">#drawable/ab_solid</item>
<item name="titleTextStyle">#style/my_title_style</item>
</style>
I donĀ“t know if it's all that ou have made, but you have to add this code in the manifest(in the activity you want to apply this style):
<activity
android:name=".MyActivity"
android:label="#string/appName"
android:theme="#style/my_little_style" >
</activity>
Try in this way:
Create a layout for your Toolbar and put a TextView:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:id="#+id/toolbar"
android:background="#b2b2b2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/toolbar_title"
android:textSize="20sp"
android:textColor="#ff282828"/>
</android.support.v7.widget.Toolbar>
Include the layout in your .xml:
<include layout="#layout/toolbar_activities"
android:id="#+id/toolbar_layout"/>
Finally set a title in your java class:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_layout);
TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
mTitle.setText("Your Title");
setSupportActionBar(toolbar)

How to change color of bar in Android App?

I'd like to change color of bar when I use this style:
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light" >
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
</style>
For example it should looks like system calculator in Android 5, I mean bar on the top is blue.
you can use
<item name="background">#color/actionbar_background_color</item>
Are you speaking about tool bar. If yes then implement the following xml in your project:
?xml version="1.0" encoding="utf-8"?>
<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/appBar"
android:background="#color/colorPrimary"
app:theme="#style/MyCustomTheme"
android:layout_width="match_parent"
android:layout_height="50dp">
</android.support.v7.widget.Toolbar>
In activity extend your activity to ActionBarActivity, then in onCreate() use the following code:
ToolBar toolbar = (Toolbar) findViewById(R.id.appBar);
setSupportActionBar(toolbar);
Make sure you give blue color for colorPrimary attribute in colors.xml file or you can directly give blue color value if you are not using colors.xml file.
Use the appCompat21 and just set this style:
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">#color/my_color</item>
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#color/my_darker_color</item>
</style>
More info here.

Changing the status bar color for Android 5.0

I've read a bunch of different posts regarding this issue but have not found anything that works. I want my app to be compatible with Android 5.0 and older versions.
For Android 5.0 I am trying to implement the status bar color change. I know this won't work for older versions though. But when I run my app on the GenyMotion VM supporting 5.0, the status bar color doesn't change to the colorPrimaryDark. It also doesn't change color in the xml preview section of Android Studio.
Here are the relevant files:
res\values\styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customize your theme here. -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/accentColor</item>
</style>
</resources>
res\values-v21\styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:colorPrimary">#color/primaryColor</item>
<item name="android:colorPrimaryDark">#color/primaryColorDark</item>
<item name="android:colorAccent">#color/accentColor</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:statusBarColor">#color/primaryColorDark</item>
</style>
</resources>
res\layout\toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primaryColor"
>
</android.support.v7.widget.Toolbar>
res\layout\activity_main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/tBar"
layout="#layout/toolbar"></include>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
MainActivity.java
public class MainActivity extends ActionBarActivity
{
private Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar=(Toolbar)findViewById(R.id.tBar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Login");
}
...
...
}
Possible issues:
I think I may have added some unnecessary items in res\values-v21\styles.xml.
Plus I thought I was supposed to make the parent = "#android:style/Theme.Material.Light.DarkActionBar" but other tutorials have it as Base.AppTheme. Also possible that I need to add more code in MainActivity.java
Can someone please help? This whole topic has me very confused.
Thanks
You could also try changing the status bar color programmatically: https://developer.android.com/reference/android/view/Window.html#setStatusBarColor(int)
Very simple program. you can do it programatically
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.BLUE);
}
maybe you can find very stupid but in my code i had that experience and your v-21 style.xml should be like this
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="colorPrimary">#color/primaryColor</item>
<item name="colorPrimaryDark">#color/primaryColorDark</item>
<item name="colorAccent">#color/accentColor</item>
</style>
</resources>
also you have to didn't define status bar color in lollipop automatically its created from Dark Primary Color. You can try this code
It'll not change status bar color if you have
<item name="android:windowTranslucentStatus">true</item>
removing this line from your app theme is the only i have found yet to change status bar color t runtime using setStausbarColor().
And still if you want to change color with android:windowTranslucentStatus then this tutorial i found useful so far link.

Android Support v7 Toolbar setTitleTextAppearance not working

I am trying to change the font of the toolbar's title.
Here is my toolbar layout:
<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_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#666666"
app:titleTextAppearance="#style/MyText"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
And in my styles.xml
<style name="MyText">
<item name="fontPath">fonts/myFont.ttf</item>
</style>
If I do not set app:titleTextAppearance, the toolbar uses the system font. When I set it, the font gets smaller, but it is still in the system font. Am I doing something wrong?
Any suggestion, comments or answers much appreciated.
Edit:
I tried moving the style to styles-text.xml but no luck
Edit2:
For now, I am using a SpannableString and TypefaceSpan to make this work. Hope it helps someone.
This works:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:titleTextAppearance="#style/ActionBarTitleStyle"/>
Then have this in your styles.xml
<style name="ActionBarTitle" parent="android:Widget.TextView">
<!-- The action bar title font -->
<item name="android:fontFamily">sans-serif-light</item>
<!-- Customizes the color of the action bar title-->
<item name="android:textColor">#FF0000</item>
<!-- Customizes the size of the action bar title-->
<item name="android:textSize">24sp</item>
</style>
In my case, the font:family is only applied if I use "android:titleTextAppearance" instead of "app:titleTextAppearance" but this only works for api 21 or higher

Categories

Resources