I'm trying to apply a gradient bg color to a WebView...
I'm use many sample code but not display gradient color...
if anyone know the ans post me..
A WebView has a default background color of white, drawn in front of any drawables. You'll need to use the following code to make it transparent:
WebView webview = (WebView)findViewById(R.id.wv);
webview.setBackgroundColor(0);
Then apply a gradient background as follows:
Create a file called gradient-bg.xml in your /res/drawable-mdpi folder.
Add:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFFFF"
android:endColor="#000000"
android:angle="90"
/>
</shape>
Then in your layout files you can add the drawable to any view or layout via the background property:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/gradient-bg"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
</LinearLayout>
put this in the drawable folder as a XML file, and then use it as a background for some Widget.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#FFFFFF" android:endColor="#AAAAAA"
android:angle="270"/>
</shape>
Try this.. Just add this XML file in ur drawable as gradient_box.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#B8E7F3"
android:endColor="#01CBFB"
android:angle="45"/>
<padding android:left="3dp"
android:top="3dp"
android:right="3dp"
android:bottom="3dp" />
<corners android:radius="6dp" />
</shape>
To make webview transperent use
webview.setBackgroundColor(0)
Related
My xml file is as follows :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:topRightRadius="50dp"
android:topLeftRadius="50dp"
/>
<solid
android:color="#color/quantum_grey"
/>
</shape>
Please help me :(
I gave the background color, But it was by no means transparent.
How to change the color orange of the edittext?
Create an xml file in drawable folder, for example:
editText_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:color="#color/desired_color" android:width="2dp"/>
</shape>
Then asign to the EditText:
<EditText
...
android:background="#drawable/editText_background"
... />
CompileSdkVersion 26, if it's important. I want to create LinearLayout with rounded corners, and background color.
I created 2 LinearLayouts, one with corners, and one with color, but their shapes do not match my expectations.
Code from activity
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/whitegrey"
android:layout_marginTop="340dp"
android:id="#+id/layout"
android:layout_marginStart="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/custom_border"
android:orientation="vertical"
android:padding="6dp"
android:textColor="#color/black">
...
</LinearLayout>
</LinearLayout>
custom_border.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"/>
<padding android:left="8dp" android:right="8dp" android:top="8dp" android:bottom="8dp"/>
<stroke android:width="2dp" android:color="#444444" />
</shape>
Actually, there is rounded border, and behind, there is rectangular layout with target color. I want to fill with target color only what is inside borders.
Is there any way to set the fill color, preferably in custom_border.xml?
Here, what I have at the moment:
Here, what I want to achieve:
View from phone, the letters on the left are cut off:
From the code samples you provide us, it doesn't seem necessary to me to have two LinearLayout. Only the layout with android:background="#drawable/custom_border" is required.
To achieve the expected result, just add the property <solid android:color="#color/whitegrey" /> to your custom_border.xml :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="20dp"/>
<padding android:left="8dp" android:right="8dp" android:top="8dp" android:bottom="8dp"/>
<stroke android:width="2dp" android:color="#444444" />
<solid android:color="#color/whitegrey" />
</shape>
I wish I was able to help you!
I have a DrawerLayout with navigation menu(there is list of menu elements), I want to change some properties. Currently it looks like this
and I need something like:
So how is it possible to change color text, imageview tint, marginLeft and small green line?
List item is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/mynavigationbackground"
android:paddingLeft="20dp"
android:layout_gravity="center_vertical">
<ImageView
android:id="#+id/navigation_item_icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/ic_menu_gallery"
android:tint="#109039"/>
<TextView
android:id="#+id/navigation_item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gallery"
android:textStyle="bold"
android:textColor="#109039"/>
</LinearLayout>
For change background color I use these xml files:
mynavigationbackground:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/navigationactivated" android:state_pressed="true"></item>
<item android:drawable="#drawable/navigationactivated" android:state_focused="true"></item>
<item android:drawable="#drawable/navigationactivated" android:state_activated="true"></item>
<item android:drawable="#drawable/navigationnoactivated"></item>
</selector>
navigationactivated:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#4064D864"></solid>
</shape>
and navigationnoactivated:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff"></solid>
</shape>
I tried to use tint and margin properties in these files but it doesn't work.
Is there any way to make this effect in xml?
I tried to do it programmatically (by onClick), but still nothing.
See this answer. it could be useful.
It is about inverted colors and I see your images and one is the opposite of the other.
Invert colors of drawable Android
I wanted to add a linear layout, having a transparent background as well as with white borders. The problem is: as far as I have googled, I can achieve only one out of both.
Here's what I did:
Saved the following as border.xml in drawable
<?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="#FFFFFF" />
</shape>
</item>
<item android:left="5dp" android:right="5dp" android:top="5dp" android:bottom="5dp" >
<shape android:shape="rectangle">
</shape>
</item>
</layer-list>
my existing page layout
<LinearLayout
android:id="#+id/quiz"
android:layout_width="150dp"
android:layout_height="120dp"
android:background="#66041414" <-------- replaced it with android:background="#drawable/border"
android:orientation="vertical"
android:layout_marginLeft="5dp" >
......
</LinearLayout>
I am getting opaque background, when the border was included.
I wanted a final result to be like:
totally stuck with it. Just wanted to find a way out to achieve it. Any suggestions would be quite helpful.
Your drawable for background of layout:
You can change radius for corner shape if you want. But stroke will create a border and solid part is the background which we are making transparent.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="2dp"
android:topRightRadius="0dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp" />
<stroke
android:width="1dp"
android:color="#android:color/white" />
<solid android:color="#android:color/transparent"/>
</shape>
and my test layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ll2"
android:layout_height="50dp"
android:layout_width="50dp"
android:background="#drawable/my_transparent_linear_layout"></LinearLayout>
</LinearLayout>
It works, Below is the proof:
For this you can use two layout aligned one top of the other then set the background transparent for the top view and set the white border as background for the bottom view. You can do this thing inside relative layouts.
Xml Drawable for background:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="30dp" />
<stroke android:width="5dp" android:color="#ffffffff"/>
<solid android:color="#66000000"/>
</shape>
Adjust radius, width and dark color transparency ( #ff and #66 parts) as you please.
Indeed well suggestion by #Ali Imran, check below way, hope it will help.
back.xml
<?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="#dd7b7a"/>
<corners android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp" android:topRightRadius="10dp"/>
<solid android:color="#dd7b7a"/>
</shape>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<LinearLayout
android:padding="4dip"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:gravity="center_horizontal"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/tile_mode" // your transparent image
/>
</LinearLayout>
</LinearLayout>
also go through below links in that, way of using xml will works for you.
Bitmap image with rounded corners with stroke