its something you may think is duplicated question but i could not found simple solution .
i want edittext to be with border when focus .
this is what i try'd , if you have simple or better solution i will be happy to read .
define shape xml :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#80000000" />
<stroke android:width="2dp" android:color="#5480F7" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
this simple <shape> create border with transparent background .
define xml for edittext :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/edittext_border" android:state_focused="true" />
<item android:drawable="#drawable/notfocus"/> <!-- default -->
</selector>
the problem here is that the xml that create the border is insert to my edittext as drawable meaning that i cant change the background image for the edittext .
i want my edittext to be with spcefic background image and when focus i want the image to stay but will be with border .
thanks .
You can achieve it by two ways:
By creating two different image for the EditText.
By creating two different shape color for the EditText.
By two different image:
Just follow Siddhesh comment to achieve this.
By Different shape for EditText:
you have done right with this way. but i think you have enter wrong background color code to solid attribute.
add:
<solid android:color="#00000000" />
instead of:
<solid android:color="#80000000" />
Hope this help you. If not then let me know. Will like to help you.
Enjoy Coding... :)
make One background image with border and other will be just background of focus set with border else without border.
Related
Here's my aching point. I'm new to android developoment and I want to create the splash screen to an app. presently, after searching in this forum, i found methods of implementing the splash screen from a picture but that's not what i want. I want the splash screen to be a color with a varying gradient. Attached to this question is a picture to illustrate what i mean.
Unfortunately, couldn't paste an image due to my low reputation points. Nonetheless, here's a link to an gradient image.
Further explaining, i want the color to be generated by either java or xml code dynamically so that, I won't have to bother about different screen sizes as all I'll have to do is to generate everything for full screen display. What's I'm trying to avoid is using picture assets if possible.
Help Plz. Thanks
create a shape, add it to drawables like : <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#color/gradient_start" <!--this first color -->
android:endColor="#color/gradient_end" <!--this second color -->
android:angle="-270" /> <!--gradient angle -->
</shape>
and then on your splash.xml background, set background to the shape
add
<LinearLayout
android:id="#+id/ranking_order"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/list_grad"
/>
Also gradients and colors may be declared directly into splash.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<!--<color android:color="#2196F3"/>-->
<shape android:shape="rectangle">
<gradient
android:startColor="#2196F3"
android:endColor="#1976D2"
android:angle="-90"
/>
</shape>
</item>
<item>
<bitmap
android:src="#drawable/logo"
android:gravity="center"
/>
</item>
</layer-list>
I tried making a 9 patch image and setting that as background as many solutions suggest but that didn't change the border color when the edittext is selected. In fact, there is no border now, just the image of the edittext. How can I simply change the border color of it? To be for example blue instead of yellow.
Try this :
According to Vikram's answer
Create a xml file with the following in drawable (say
backwithborder.xml):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#00000000" />
<stroke android:width="1dip" android:color="#ffffff" />
</shape>
and for the EditText user attribute
android:background="#drawable/backwithborder"
Other answers that may help you :
Change edittext border color
How to set border color for EditText
You need to make a selector when the Edittext is focused or selected the image changes of the Edittext.
sample:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_pressed="true"
android:drawable="#android:drawable/edittext_pressed"/> //9patch for pressed
<item
android:state_focused="true"
android:drawable="#drawable/edittext_focused"/> //9patch for focused
<item
android:drawable="#android:drawable/edittext_normal"/> //9patch for normal
</selector>
This selector is then added in the background of the Edittext.
Use the below step to change the border color.
editText.Background.SetColorFilter(Color.Red);
This question already has an answer here:
How to add border to listview and different row colors at the same time
(1 answer)
Closed 8 years ago.
I have a scrollable listview. I need to highlight the top and bottom border of the row like this .As am a newbie tell me how to do this. Thanks in advance
android:listSelector="#drawable/list_selectorcolor"
In drawable create like this
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="#000000"
android:startColor="#000000"
android:type="linear"/>
<stroke
android:width="1dp"
android:color="#800080"
android:dashWidth="2dp"/>
</shape>
Create a selector file like this for different states of list view under drawable folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/app_tint_pressed"
android:state_selected="true"/>
<item android:drawable="#color/app_tint_pressed"
android:state_pressed="true" />
<item android:drawable="#color/app_tint" />
</selector>
Apply this file like this under ListView in xml
android:listSelector = #drawable/myselector
For different states check state list on this link http://developer.android.com/guide/topics/resources/drawable-resource.html
you can use nine-patch images and color as well for different states in your case the normal state is black color and for pressed state either create a nine-patch image with black and borders you want or you can create it in xml as well
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#android:color/white"/>
<stroke
android:width="2dp"
android:color="#800080"
android:dashWidth="2dp"/>
Just add following detail in the listview in xml file
android:divider="#FF3366"
android:dividerHeight="3dp"
Try this according to your code
viewHolder.imageview.setText(entry.getString("calculator"));
if(position % 2 == 0){
viewHolder.linearLayout.setBackgroundResource(R.color.grey);
}
else{
//viewHolder.linearLayout.setBackgroundResource(R.color.white);
}
It will change the color of row
set the view's background to a xml file. in resource drawable we can use xml files. check the Api demos drawable folder. that xml file contains this code.
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false"
android:drawable="#drawable/button_image_in_normal_state" />
<item android:state_pressed="true"
android:drawable="#drawable/button_image_in_pressed_state_with_border" />
</selector>
and assign this xml filename in view's background.
also refer this link
I want the imagebutton to appear transparently on the screen so i have made android:background="#null" in the XML file so it has removed the gray border around the imagebutton.It solved my problem but when i click on the imagebutton it is not showing any background color. But i need some background color to appear on click. So I have added android:padding="3dp". It has removed the border on the sides but not on the top.
<ImageButton
android:id="#+id/btnphoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/photo"
android:layout_x="4px"
android:layout_y="370px"
android:padding="3dp" />
Please help me.
Thanks in advance.
To change View aspect on state changes (click, press, focus, ...) you can use StateListDrawable as android:background. ColorStateList can be usefull too.
This post shows a good example of how to use.
android:background="#android:color/transparent"
or, if you want only some transparency, you can control it with the alpha channel.
Something like
android:background="#7F000000"
would be a partially transparent black.
You can try making your custum button background, using images or shapes in XML...
For example, this shape make one button state where the colors are transparent because they are ARGB type.
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#EB363636" />
<corners
android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
<stroke
android:width="2dip"
android:color="#D1000000" />
</shape>
Then you can combine multiple shapes/images to make an button react the diferent states:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:dither="true">
<item
android:state_window_focused="false"
android:drawable="#android:color/transparent" />
<item
android:state_pressed="true"
android:drawable="#layout/shape_btn"/>
<item
android:state_focused="true"
android:drawable="#layout/shape_btn"/>
<item
android:drawable="#android:color/transparent"/>
</selector>
After making your selector you can use it as your button background using android:background="NAME OF SELECTOR FILE"
Friends How To Display Border To Imageview ?
I Want To Result Like Mobile gallery all image display with border.
plz give me ans thanks for advance....
You can create a resource (layer drawable xml) for your ImageView's "border" (actually background), and declare in your theme that the ImageView's background resource is the drawable xml.
If you need this "border" to be changed based on the ImageView's state (focused, selected, etc.), then you should create more layer drawables, and put them together into a selector xml (state drawable).
Then in your theme you should set the ImageView's background to be this selector.xml.
Update
Below is a sample of how to specify a simple border to your images, that will result in
You have to
create a new layer drawable file (image_border.xml),
modify/create your styles.xml file
modify/create your colors.xml file
modify your layout xml file (or your code) to apply the style to the ImageView.
res/drawable/image_border.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient android:angle="90"
android:startColor="#color/image_border_start"
android:centerColor="#color/image_border_center"
android:endColor="#color/image_border_end" />
</shape>
</item>
<item android:top="2dp" android:left="2dp"
android:right="2dp" android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#color/default_back_color" />
</shape>
</item>
</layer-list>
res/values/styles.xml
Add the following lines:
<style name="myImageView">
<!-- 3dp so the background border to be visible -->
<item name="android:padding">3dp</item>
<item name="android:background">#drawable/image_border</item>
<item name="android:scaleType">fitCenter</item>
</style>
res/values/colors.xml
Add the following lines:
<color name="image_border_start">#40990000</color>
<color name="image_border_end">#FF660000</color>
<color name="image_border_center">#FFFF3333</color>
And finally specify the style of your ImageView in your layout xml:
<ImageView android:id="#+id/my_image"
android:layout_width="100dp" android:layout_height="100dp"
android:src="#drawable/efteling"
style="#style/myImageView" />
You can use this XML file as a drawable instead of multiple files, but this
file is placed in drawable folder. In ImageView use this XML file as a
background drawable, like: android:background="#drawable/following code file
name".
I hope this is helpful for you.
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
I tried all the above solutions but they didn't work for me!
So I figured out a simple solution to this! :-)
I remember that I read about FrameLayout of Android in the following article saying that it helps us to stack up our UI elements on top of each other in the same order we add them up.
Solution:
<FrameLayout
android:layout_width="112dp"
android:layout_height="112dp"
android:layout_marginLeft="16dp" <!-- May vary according to your needs -->
android:layout_marginRight="16dp" <!-- May vary according to your needs -->
android:layout_centerVertical="true">
<!-- following imageView acts as the boarder which sitting in the background of our main container ImageView -->
<ImageView
android:layout_width="112dp"
android:layout_height="112dp"
android:background="#000"/>
<!-- following imageView holds the image as the container to our image -->
<!-- layout_margin defines the width of our boarder, here it's 1dp -->
<ImageView
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_margin="1dp"
android:id="#+id/itemImageThumbnailImgVw"
android:src="#drawable/banana"
android:background="#FFF"/>
</FrameLayout>
Preview:
And that's it. You will get the following like imageView!
Pros and Cons:
I think this is pretty easy solution to be used in anywhere else and it's all the things you do sits in one single place so easier to modify it. However I don't like to having to add two ImageViews.