Status bar has no shadow - android

I have tried to move my content below the status bar with success. Used the following code:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
But the issue is that i have no status bar shadow. How do i achieve it?

shadows_bottom.xml design and color the way you like it to be
<item name="android:windowContentOverlay">#drawable/shadows_bottom</item>
Example shadows_bottom.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape
android:shape="rectangle">
<solid android:color="#android:color/darker_gray" />
<corners android:radius="5dp"/>
</shape>
</item>
<item android:right="1dp" android:left="1dp" android:bottom="2dp">
<shape
android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
And you also need to set colorPrimary and colorPrimaryDark following official guidelines
here: https://www.materialpalette.com

Add this line in your style.xml code theme:
<item name="android:windowContentOverlay">#null</item>

In Api > lollipop you can set statusBar color, and it haven't any shadows.
Just write in your xml with theme:
<item name="colorPrimary">#color/toolbar_color</item>
<item name="colorPrimaryDark">#color/status_bar_color</item>

Related

Change 1 button color after being selected out of 4 buttons there are, and then change to normal again if other button selected

So i have 4 buttons, and i want to make if one button is clicked by the user it will change its color to red and stay that way until if the user pressed the other 3 buttons
enter image description here
i have read other post about this, but they showed to me to use selector state_selected and etc, but it doesnt work for me. and the other use setBackground in the java code, but i will be using 8 buttons and probably more, and its not going to be efficient to do it that way, is there any more efficient way to do this?
this is the code i have on the drawable xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle" >
<solid android:color="#color/red_maroon"/>
<stroke android:color="#color/red_maroon" android:width="1dp"/>
<corners android:radius="8dp"/>
</shape>
</item>
<item android:state_selected="true">
<shape android:shape="rectangle" >
<solid android:color="#color/red_maroon"/>
<stroke android:color="#color/red_maroon" android:width="1dp"/>
<corners android:radius="8dp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle" >
<solid android:color="#color/white"/>
<stroke android:color="#color/red_maroon" android:width="1dp"/>
<corners android:radius="8dp"/>
</shape>
</item>
</selector>
If selector state_selected does not work, check if your button style has this attribute: <item name="android:selectable">true</item>
The style:
<style name="AppButtonOutlineSelectable" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="shapeAppearance">#style/AppButtonShape</item>
<item name="strokeColor">#color/color_selectable_button_stoker_selector</item>
<item name="android:selectable">true</item>
<item name="strokeWidth">1dp</item>
<item name="backgroundTint">#color/color_selectable_button_bg</item>
</style>
<style name="AppButtonShape" parent="ShapeAppearance.MaterialComponents.SmallComponent">
<item name="cornerSize">8dp</item>
</style>
And use color selector under color directory, not drawable selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/red" android:state_selected="true" />
<item android:color="#color/white" />
</selector>
The button:
<com.google.android.material.button.MaterialButton
android:id="#+id/btn"
style="#style/AppButtonOutlineSelectable"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Set onClick:
btn.setOnClickListener {
btn.isSelected = btn.isSelected.not()
}

Not able to change radio button circle color in android

I am using radioButton in my app but by default my radioButton color is black and when I select it that turns to color accent color that I have mentioned in my color.xml but I want to change radioButton initial color and selected color to white color. How I am able to do so. I tried background color but it changes background color property. Please help.
First Put this code in style.xml
<!-- custom style -->
<style name="radionbutton"
parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:button">#drawable/rb_drawable</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
Now make rb_drawable.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/radio_unchecked" android:state_checked="false" android:state_focused="true"/>
<item android:drawable="#drawable/radio_unchecked" android:state_checked="false" android:state_focused="false"/>
<item android:drawable="#drawable/radio_checked" android:state_checked="true" android:state_focused="true"/>
<item android:drawable="#drawable/radio_checked" android:state_checked="true" android:state_focused="false"/>
</selector>
Now make 2 more files for radio button check/uncheck in drawable folder
radio_unchecked.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke android:width="1dp" android:color="#color/colorAccent"/>
<size android:width="30dp" android:height="30dp"/>
</shape>
radio_checked.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:width="1dp" android:color="#color/colorAccent"/>
<size android:width="30dp" android:height="30dp"/>
</shape>
</item>
<item android:top="5dp" android:bottom="5dp" android:left="5dp" android:right="5dp">
<shape android:shape="oval">
<solid android:width="1dp" android:color="#color/colorAccent"/>
<size android:width="10dp" android:height="10dp"/>
</shape>
</item>
</layer-list>
Finally change style of radio button in layout xml
<RadioButton
android:layout_width="wrap_content"
style="#style/radionbutton"
android:checked="false"
android:layout_height="wrap_content"
/>

Android tabs textcolor selector ignores state_pressed

I have created my own android theme to change the look of the actionbar tabs. The problem is that textcolor selector seems to ignore state_pressed attribute, so the color of tab text is always the same, even if this tab is pressed. There is no problem with other states, for example state_selected is correctly recognized and selected tab has text color, which is different from unselected tabs text color.
What is more, i have also created selector for tabs background and it works fine with state_pressed (if the tab is pressed, it's backround color is changed).
There are some pieces of my code:
styles.xml:
<style name="Theme.MyTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarTabStyle">#style/Theme.MyTheme.TabStyle</item>
<item name="android:actionBarTabTextStyle">#style/Theme.MyTheme.TabTextStyle</item>
</style>
...
<style name="Theme.MyTheme.TabStyle"
parent="#android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#drawable/background_selector</item>
</style>
<style name="Theme.MyTheme.TabTextStyle"
parent="#android:style/Widget.Holo.Light.ActionBar.TabText">
<item name="android:textColor">#color/textcolor_selector</item>
</style>
background_selector.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false" android:state_pressed="false">
<shape>
<solid android:color="#00ff00"/>
</shape>
</item>
<item android:state_selected="false" android:state_pressed="true">
<shape>
<solid android:color="#0000ff"/>
</shape>
</item>
<item android:state_selected="true" android:state_pressed="false">
<shape>
<solid android:color="#ff0000"/>
</shape>
</item>
<item android:state_selected="true" android:state_pressed="true">
<shape>
<solid android:color="#ffff00"/>
</shape>
</item>
</selector>
textcolor_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:state_pressed="false"
android:color="#ff0000"/>
<item android:state_selected="true" android:state_pressed="true"
android:color="#0000ff"/>
<item android:state_selected="false" android:state_pressed="false"
android:color="#ffff00"/>
<item android:state_selected="false" android:state_pressed="true"
android:color="#00ff00"/>
</selector>
I have tried everything without success - state_pressed attribute seems to be ignored, but only in textcolor_selector. Please, help me understand and solve this problem.
Review the Customize the Text Color section of the ActionBar Styling documentation - it mentions that Note: The custom style applied to titleTextStyle should use TextAppearance.Holo.Widget.ActionBar.Title as the parent style. - perhaps a change there might help correct the problem.
Another place to look would be here under the Example theme section - it shows an example of android:actionBarTabTextStyle that might help get things sorted for you.
Try this in the drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true">
<shape>
<corners android:radius="0dp" />
<solid android:color="#color/white" />
<stroke android:width="1dp" android:color="#color/color_700" />
<padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" />
</shape>
</item>
<item android:state_enabled="false">
<shape>
<corners android:radius="0dp" />
<solid android:color="#color/color_100" />
<stroke android:width="1dp" android:color="#color/bloqueado" />
<padding android:bottom="1dp" android:left="1dp" android:right="1dp" android:top="1dp" />
</shape>
</item>
</selector>

How do I style RelativeLayout from styles.xml - Android

I am trying to style a RelativeLayout from styles.xml because I have different themes and I am trying to change it's background. How do I do that?
I know that styling a ListView goes like this (for example):
<style name="Theme_Day" parent="Theme.Sherlock.Light">
<item name="android:textColor">#color/def_actionbar_submenu_text</item>
<item name="android:listViewStyle">#style/def_ListView</item>
<item name="vpiTabPageIndicatorStyle">#style/CustomTabPageIndicator</item>
</style>
<style name="def_ListView" parent="#android:style/Widget.ListView">
<item name="android:background">#drawable/listview_bg</item>
<item name="android:textColor">#color/def_listview_title_text</item>
<item name="android:divider">#color/def_listview_itemdivider_bg</item>
<item name="android:dividerHeight">#dimen/listview_divider_height</item>
</style>
but when I try to find "android:relativeLayoutStyle" or parent="#android:style/Widget.RelativeLayout" I cant find anything..
How do I do that?
This question has been asked before a long time ago, but you can always try like this:
<style name="RelativeLayoutStyle" parent="#android:style/Widget">
<item name="android:layout_marginLeft">10dp</item>
<item name="android:layout_marginTop">7dp</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:background">#android:color/holo_green_dark</item>
</style>
Now you can do:
<RelativeLayout
style="#style/RelativeLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
Hope this helps someone.
You don't need any parent just write
<style name="def_RelativeLayout">
<item name="android:background">#drawable/listview_bg</item>
</style>
and set it in your style attribute of every relative layout
Create a drawable file and then set android:background with the #drawable/layout_style property.
For example, this drawable file is used to create a Google Card like design:
background_card.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="2dp"/>
<solid android:color="#ccc" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle"
android:dither="true">
<corners android:radius="2dp" />
<solid android:color="#android:color/white" />
<padding android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp" />
</shape>
</item>
</layer-list>
And from the layout XML file, you need to set the android:background property:
android:background="#drawable/backgorund_card"
_
<RelativeLayout
android:id="#+id/layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backgorund_card" >

customizing action bar sherlock

I have implemented Action bar Sherlock with theme.sherlock. The action bar has navigation tab. I have used styles for customizing the action bar. The style xml is shown below
<resources>
<style name="MyTheme" parent="Theme.Sherlock">
<item name= "actionBarStyle">#style/ActionStyle</item>
<item name="actionBarTabTextStyle">#style/MyTabTextStyle</item>
</style>
<style name= "ActionStyle" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#drawable/actionstyle</item>
<item name="background">#drawable/actionstyle</item>
</style>
<style name="MyTabTextStyle" parent="Widget.Sherlock.ActionBar.TabText" >
<item name="android:textColor">#0EBFE9</item>
<item name ="android:textStyle">bold</item>
<item name= "android:textSize">14dp</item>
</style>
</resources>
the drawable action style
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Bottom Line -->
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/darker_gray"/>
</shape>
</item>
<!-- Color of your action bar -->
<item android:bottom="2dip">
<shape android:shape="rectangle">
<solid android:color="#android:color/darker_gray" />
</shape>
</item>
</layer-list>
I need to
remove the divider between action bar and navigation tab
show blue divider below the navigation tab
All you have to do is setting the background property of your xml. You can set the "color" transparent to remove it.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Bottom Line -->
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/transparent" />
</shape>
</item>
<!-- Color of your action bar -->
<item android:bottom="2dip">
<shape android:shape="rectangle">
<solid android:color="#color/action_bar_color" />
</shape>
</item>
</layer-list>
Afterwards apply it in your theme:
<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#drawable/action_bar_background</item>
<item name="background">#drawable/action_bar_background</item>
</style>

Categories

Resources