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"
... />
Related
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 have xml file in drawable folder for rounded button - rounded.xml.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ccc" />
<corners android:radius="5dp" />
<stroke android:width="1dp" android:color="#000" />
</shape>
Usually I set it by using android:background = "#drawable/rounded" inside button xml, but I would like to create few xml files with different colors so that I could change app theme.
Do you know how should I set background for button, but in java?
This should work:
Button button = (Button) findViewById(R.id.myButton);
button.setBackgroundResource(R.drawable.rounded);
I have a listview and i want to when i click on a row, its background changes to blue. i use this code:
listView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
parent.getChildAt(position).setBackgroundColor(Color.BLUE);
}
});
this works wit some wrong. when i click on first item, it turns to blue but item #3 and #5 changes to blue too!!! i cant understand why!! i just want only selected item turns to blue!!!
What about to use selectors? They works properly and provide clean solution.
listselector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="#drawable/normal" />
<item
android:state_selected="true"
android:state_focused="false"
android:drawable="#drawable/hover"
/>
<item
android:state_selected="true"
android:state_pressed="false"
android:drawable="#drawable/hover" />
</selector>
normal.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid
android:color="#cccccc"
/>
</shape>
hover.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid
android:color="#dddddd"
/>
</shape>
An Usage
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="#drawable/listselector"
/>
Key property is to set android:listSelector="#drawable/listselector" for your ListView.
Note:
You can use in shape also gradient property instead of solid color. And for more details also you can look at tutorial Android Custom ListView.
If you have a custom list view then use the below code.
public View getView(final int arg0, View arg1, ViewGroup arg2) {
final ViewHolder vh;
vh= new ViewHolder();
if(arg1==null )
{
arg1=mInflater.inflate(R.layout.lyourcustomlayouttobe inflated, arg2,false);//custom layout inflated
arg1.setTag(vh);
}
return arg1;
}
Your custom layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:cacheColorHint="#000000"
android:background="#drawable/listviewbkg">
//other items to be inlfated.
</LinearLayout>
Create a drawable folder under resources. post the below xml as listviewbkg
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/pressed" />
<item android:state_focused="false"
android:drawable="#drawable/normal" />
</selector>
Shape when normal under drawable with name normal.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>//change color
<stroke android:width="3dp"
android:color="#0FECFF" /><!-- #330000FF #ffffffff -->//border color
<gradient // remove the gradient if do not wish to use.
android:startColor="#ffffffff"
android:endColor="#110000FF"
android:angle="90"/>
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<corners android:bottomRightRadius="7dp" // change this to increase the rounded edge radius
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
Shape when pressed under the name pressed.xml in drawable folder
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FF1A47"/> //change color
<stroke android:width="3dp"
android:color="#0FECFF"/>//border color
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<corners android:bottomRightRadius="7dp"// increase the radius at the edge
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
use listselectors to achieve this goal:
Hree is an example:
http://www.michenux.net/android-listview-highlight-selected-item-387.html
and if you want your listview item color permanent, then, you need to create an array of selected positions, an in getview() method of your cutom adapter, you need to check if that position is exists in array or not, if yes, then change background color of your view manually
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
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)