ActionBarSherlock set gradient background - android

Hi i'm wanting to set a gradient background on ActionBarSherlock i'm currently setting this in the theme as a shape drawable but when i run it it just has a white background does anyone know what i'm doing wrong or how to do this?
heres my style(i have declared this in the manifest file)
<style name="MyTheme.ActionBarStyle" parent="Widget.Sherlock.ActionBar">
<item name="background">#drawable/bg_actionbar</item>
<item name="android:background">#drawable/bg_actionbar</item>
</style>
<style name="Theme.SherlockCustom" parent="#style/Theme.Sherlock.Light">
<item name="actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
and heres my drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:type="radial"
android:gradientRadius="400"
android:startColor="#FF0000"
android:endColor="#0000FF" />
</shape>

Everything is cool only that the xml gradient element should look like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="270"
android:startColor= "#FF0000"
android:centerColor="#FF0000"
android:endColor="#0000FF" />
</shape>

Related

TextInputLayout with outline but transparent background

If boxBackgroundColor is transparent then boxStroke is invisible
<style name="OutlinedRoundedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxBackgroundColor">#android:color/transparent</item>
<item name="boxStrokeColor">#android:color/white</item>
<item name="boxStrokeWidth">4dp</item>
</style>
So is it only possible to have transparent TextInputLayout without outline using custom background?
E.g.:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="5dp" />
<stroke
android:width="2dp"
android:color="#color/colorEditTextOutline" />
</shape>
</item>
</layer-list>
If you had posted a design for it then it would have been easier understand. For this solution If I understand you correctly, you need to add these two things
In style add:
<style name="InputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxStrokeColor">#color/text_input_box</item>
</style>
Add color resource:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#color/red_bright" android:state_focused="true" />
<item android:color="#color/red_bright" android:state_hovered="true" />
<item android:color="#color/red_bright" />
</selector>
This solution will have something like this if this is what you want

Customize webview scrollbar

I have to customize scrollbar in webview - change track and thumb colors, shapes (simple rectangles). I couldn't find any information about customizing webview scrollbar, only listviews.
So far, i created:
styles.xml
<style name="CustomScrollBar">
<item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
<item name="android:scrollbarStyle">outsideOverlay</item>
<item name="android:scrollbars">vertical</item>
<item name="android:fadeScrollbars">true</item>
<item name="android:scrollbarThumbVertical">#drawable/custom_scrollbar_thumb</item>
<item name="android:scrollbarTrackVertical">#drawable/custom_scrollbar_track</item>
<item name="android:scrollbarSize">12dp</item>
<item name="android:scrollbarFadeDuration">2000</item>
<item name="android:scrollbarDefaultDelayBeforeFade">1000</item>
</style>
drawable/custom_scrollbar_track.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="0"
android:endColor="#color/gray"
android:startColor="#color/gray" />
<corners android:radius="6dp" />
</shape>
drawable/custom_scrollbar_thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="0"
android:endColor="#color/green"
android:startColor="#color/green" />
<corners android:radius="6dp" />
</shape>
However, wv.setScrollBarStyle(R.style.CustomScrollBar); gives me an error:
Must be one of: View.SCROLLBARS_INSIDE_OVERLAY,
View.SCROLLBARS_INSIDE_INSET, View.SCROLLBARS_OUTSIDE_OVERLAY,
View.SCROLLBARS_OUTSIDE_INSET
It was easier than i thought.
Just added
android:scrollbarThumbVertical="#drawable/custom_scrollbar_thumb"
android:scrollbarTrackVertical="#drawable/custom_scrollbar_track"
attributes to my webview in layout file. Of course i had to remove corners attributes from drawable files.

Android Ripple Effect Overridden by Selected State

After having been looking for a while I've not been able to find an answer to this...
I have a recycler view with items which when selected have a red background and white text (beforehand the background is white and text is black). To do this I am using a selector.
I have recently tried to add a ripple effect to this, but unless I long click on the item the background of the item goes straight to red without the ripple. I am assuming this is because the selector state state_selected overrides the ripple on sate_pressed?
Does anyone know if there is a way around this? Here is the selector code I use:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#android:color/holo_red_dark" >
<item>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="#drawable/ripple"
android:state_pressed="true"/>
<item
android:drawable="#android:color/holo_red_dark"
android:state_selected="true"/>
<item android:drawable="#android:color/white"/>
</selector>
</item>
</ripple>
Thanks in advance!
To create a selector background that has a ripple effect and shows selected status I do the following:
Start by defining your highlight color, with some transparency:
values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="selector_color">#660000ff</color>
</resources>
You probably want to have compatibility pre-lollipop. Put a typical old-school selector inside drawable folder:
drawable/selector_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/selector_color" android:state_pressed="true"/>
<item android:drawable="#color/selector_color" android:state_selected="true"/>
<item android:drawable="#android:color/transparent"/>
</selector>
And then add the following layer drawable inside drawable-v21 folder:
drawable-v21/selector_background.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<selector>
<item android:state_selected="true"
android:drawable="#color/selector_color" />
<item android:drawable="#android:color/transparent" />
</selector>
</item>
<item>
<ripple android:color="#color/selector_color">
<item android:id="#android:id/mask">
<color android:color="#android:color/white" />
</item>
</ripple>
</item>
</layer-list>
Now you can use #drawable/selector_background for your selector.
So I have another case in which I had to use selector as well as layer list for that
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/colorRipple">
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#color/grey_very_light" />
</shape>
</item>
<!-- ripple color -->
<item android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#color/c_unread_notifications_item" />
</shape>
</item>
</layer-list>
</item>
</ripple>
</item>
<item>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/colorRipple">
<item>
<!-- ripple color -->
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#color/grey_very_light" />
</shape>
</item>
<item android:bottom="1dp">
<shape android:shape="rectangle">
<solid android:color="#color/white" />
</shape>
</item>
</layer-list>
</item>
</ripple>
</item>
</selector>
This worked, for your need what you can do it just replace the item under ripple with your item shape if you don't have any layering.
Hope this helps
It will be better if you wrap your recyclerview item view in FrameLayout and set android:background="?selectableItemBackground" of FrameLayout and the child layout of FrameLayout background="#drawable/background"
background.xml
<item android:drawable="#color/red" android:state_selected="true"/>
<item android:drawable="#color/red" android:state_focused="true"/>
<item android:drawable="#color/red" android:state_pressed="true"/>
<item android:drawable="#color/white"/>
And then child layout must has attribute android:duplicateParentState="true"

Scrollbar track style android

I have a Listview and I want to give the scrollbar a style :
<style name="scrollbar">
<item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
<item name="android:scrollbarStyle">outsideOverlay</item>
<item name="android:scrollbars">vertical</item>
<item name="android:fadeScrollbars">true</item>
<item name="android:scrollbarThumbVertical">#drawable/apptheme_fastscroll_thumb_holo</item>
</style>
This works fine :P but no track here I would like it scrollbarVertical Track to be black thin line. I tried this drawable for line :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<stroke android:width="1dp" android:color="#android:color/black"/>
<size android:width="2dp" />
</shape>
But if I append this to scrollbar style like
<item name="android:scrollbarTrackVertical">#drawable/track</item>
I cant see the thumb ...
It looks like you're missing transparency on the track drawable, so the thumb isn't visible when the style is applied. Try adding this to your #drawable/track.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- add transparency to ensure thumb visibility -->
<solid
android:color="#00000000" />
<stroke
android:width="1dp"
android:color="#android:color/black" />
<size
android:width="2dp" />
</shape>

Issue in Title bar Customization

I have created a customized title. The supported xmls are
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="CustomWindowTitleBackground" />
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground
</item>
</style>
</resources>
customtitle.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:endColor="#color/grey7"
android:startColor="#color/black" />
<corners
android:bottomLeftRadius="12dp"
android:bottomRightRadius="12dp"
android:topLeftRadius="12dp"
android:topRightRadius="12dp" >
</corners>
</shape>
The resultant title bar should be rounded from four corners but it is only rounded on top left and top right.
How to make it rounded on all corners???
you can use android:background to control the round effect:
for example:
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="270"
android:startColor="#color/bar_more_main_start"
android:endColor="#color/bar_more_main_end" />
<corners
android:bottomLeftRadius="6dip"
android:bottomRightRadius="6dip"
android:topLeftRadius="6dip"
android:topRightRadius="6dip" />
</shape>

Categories

Resources