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
Related
I want to add shadow effect to my ImageView, like a transparent from bottom side. Here two images with and without shadow effect. Has any possible ways to make like this? Or is it better to take shadow svg file from the internet and put on the original imageView?
You can put your image in the same space with a gradient image using a RelativeLayot like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/your_image"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/grad"/>
</RelativeLayout>
The "grad" image is this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="270"
android:endColor="#181818"
android:startColor="#00000000 " />
<corners android:radius="5dp" />
</shape>
I'm hoping there is an xml solution to this... I am trying to create a layout that has rounded corners and then filling that layout with an image (tiled, repeat). So basically I have a LinearLayout that has a drawble layered-list assigned to the background. Here is the test layout (xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/rate_buttons"
android:layout_width="100dp"
android:layout_height="50dp"
android:orientation="horizontal"
android:padding="0dp"
android:background="#drawable/test_rounded">
</LinearLayout>
</LinearLayout>
here is the test_rounded drawable xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item ><bitmap android:src="#drawable/my_tiled_image" android:tileMode="repeat"/></item>
<item >
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:width="3dip" android:color="#B1BCBE" />
<corners android:radius="20dip"/>
</shape>
</item>
</layer-list>
The image is overflowing at the corners of the shape/layout border. I get the following
As you can see the corners are overflowed. I heard about modifying the image part (blue pattern) in code but I have issues with that since I do modify it and animate it along the way. SO, if its at all possible to just fill in the layout with that image, please let me know. Thank you all for your help.
You can do this only programatically. But if you want to do this using xml, you have to add the background image in a layout above the rounded corner layout with the help of Relative layout and set margin. This will not give a perfect solution but will solve your problem.
The first is the XML way
Create an xml file in your respective drawable folder for the round border.
I have namedd it as popupborder.xml.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<stroke android:width="2dp" />
<corners android:radius="15dip" />
</shape>
The main layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="#drawable/popupborder" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp" >
<LinearLayout
android:id="#+id/property_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Inner view with Background and margin"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
i recommend you to use an image loader library such as universal image loader, picasso etc. Here is an example code for it:
String url = "file://" + your_file_path
com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(url, ivPicture, options);
You have to add
.displayer(new RoundedBitmapDisplayer(px))
to your Universal Image Loader display options.
Also there is another library (i think this is what you are looking for) https://github.com/vinc3m1/RoundedImageView
You can check this. But in second way you can get "Out of Memory Exception" cause of loading big sized image.
I hope this'll help you.
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
When I try clicking on a a listview item no selector is shown. Here is my ListView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/streamRelativeLayout">
<ListView android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="#+id/streamListView" android:cacheColorHint="#00000000" android:fadingEdge="none" android:listSelector="#drawable/swipeview_list_selector"> </ListView>
<TextView android:layout_centerInParent="true" android:layout_height="wrap_content" android:id="#+id/noStreamTextView" android:layout_width="wrap_content" android:text="No Stream Available" android:visibility="invisible"></TextView>
<ProgressBar android:layout_centerInParent="true" android:layout_height="wrap_content" android:id="#+id/streamProgressBar" android:layout_width="wrap_content"></ProgressBar>
</RelativeLayout>
Here is my selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_focused="true"
android:drawable="#drawable/stocks_gradient" />
<item android:state_pressed="true"
android:drawable="#drawable/stocks_gradient" />
<item android:state_focused="true"
android:drawable="#drawable/stocks_gradient" />
</selector>
Here is the gradient:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#ECECEC"
android:centerColor="#F6F6F4"
android:endColor="#F8F8F6"
android:angle="90"
android:dither="true"
/>
</shape>
I am also setting the background color to alternate in getView()
int colorPos = position % colors.length;
v.setBackgroundColor(colors[colorPos]);
If you mean that selected item is not displayed the way you want, then that's because you missed the state_selected case:
<item android:state_selected="true" android:drawable="..."/>
The first issue I see is that all of your states use the same drawable, so you wouldn't see a change when you click on it. And you haven't accounted for all of the cases, for example you have no default state.
i need to set the selectorontop property to true.
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)