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.
Related
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
I have defined the below files in res folder.
styles_apptheme.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="ButtonAppTheme" parent="android:Widget.Holo.Light.Button">
<item name="android:background">#drawable/apptheme_btn_default_holo_light</item>
</style>
</resources>
themes_apptheme.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="#style/_AppTheme"/>
<style name="_AppTheme" parent="Theme.AppCompat.Light">
<item name="android:editTextBackground">#drawable/apptheme_edit_text_holo_light</item>
<item name="android:buttonStyle">#style/ButtonAppTheme</item>
</style>
</resources>
In my Layout.xml file, i have defined my button as below
<Button
android:id="#+id/btnAddTitle"
android:layout_below="#id/edEnterTitleValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_AddTitle"
android:layout_margin="20dp"
/>
If i add the below line to the button view above,
android:background="#style/ButtonAppTheme"
Application crashes saying that drawable resource should be set for the background attribute.
So i created the below drawable file - abc.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/apptheme_btn_default_normal_holo_light" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/apptheme_btn_default_disabled_holo_light" />
<item android:state_pressed="true"
android:drawable="#drawable/apptheme_btn_default_pressed_holo_light" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/apptheme_btn_default_focused_holo_light" />
<item android:state_enabled="true"
android:drawable="#drawable/apptheme_btn_default_normal_holo_light" />
<item android:state_focused="true"
android:drawable="#drawable/apptheme_btn_default_disabled_focused_holo_light" />
<item
android:drawable="#drawable/apptheme_btn_default_disabled_holo_light" />
</selector>
If i set android:background="#drawable/abc" i dont see the style set in the button.
So please let me know how i can set the style for the button.
Thanks.
It would be rather simple if you do it this way.
First create a button_selector.xml in drawable folder.
<?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" >
<corners android:radius="5dp" />
<stroke android:width="1dip" android:color="#color/green_temp" />
<gradient android:angle="-90" android:startColor="#color/green_temp" android:endColor="#color/green_temp" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="5dp" />
<stroke android:width="1dip" android:color="#971E05" />
<solid android:color="#58857e"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="5dp" />
<stroke android:width="1dip" android:color="#color/bright_green" />
<gradient android:angle="-90" android:startColor="#color/green_temp" android:endColor="#color/button_green" />
</shape>
</item>
</selector>
Add these colors in colors.xml of values folder.
<!-- Green -->
<color name="green_temp">#23A96E</color>
<color name="green_dark">#159204</color>
<color name="bright_green">#02D8B0</color>
<color name="button_green">#10a54a</color>
Finally in your desired button of layout.xml put background from above selector.
<Button
android:id="#+id/btnAddTitle"
android:layout_below="#id/edEnterTitleValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_AddTitle"
android:background="#drawable/button_selector"
android:layout_margin="20dp"
/>
Then its all done your button will be styled with color you want.
Android Button Maker is online tool to generate buttons code for Android Apps. Android API provide Drawable Resources where XML file defines geometric shape, including colors, border and gradients.
These button is generating based on shape drawable XML code which load faster compare to normal png buttons. You can customize button properties in setting panel and get source code.
Check this link Button Maker
No need to crack brains...this tool make it simple
replace
android:background="#style/ButtonAppTheme"
with
style="#style/ButtonAppTheme"
and every thing is ok!
Try this out as alternative. create a drawable folder under res then create xml files and copypaste below code and try first then you customize as per your requirement.
button_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#00acc1"/>
<stroke android:width="2dp" android:color="#ffffff"/>
<corners android:radius="2dp"/> </shape>
button_bg_pressed.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#006064"/>
<stroke android:width="1dp" android:color="#ffffff"/>
<corners android:radius="2dp"/> </shape>
button_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true" android:state_pressed="true"
android:drawable="#drawable/button_bg_pressed" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="#drawable/button_bg_pressed" />
<item android:drawable="#drawable/button_bg" /> </selector>
And now in your button xml set the background as button_selector.xml
<Button
android:id="#+id/btnAddTitle"
android:layout_below="#id/edEnterTitleValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/btn_AddTitle"
android:background="#drawable/button_selector"
android:layout_margin="20dp"/>
This will do the job for you. You can customize your entire button style by this way.
If you want to have the default animation of button by material design and change button color, try this.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/padding_12"
android:text="button text here"
android:theme="#style/NavyBtn" />
in style.xml
<style name="NavyBtn" parent="Theme.AppCompat.Light">
<item name="colorButtonNormal">#020e39</item>
<item name="android:textColor">#FFFFFF</item>
</style>
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>
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>
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>