Hi I wanna set set background gradient for button with kotlin in programming not use XML
how I can create it ?
like this
image
If you don't want to use XML, then you'll have to at least include an image asset that contains such background into the drawable folder of your application.
Once you do that, it should be as simple as calling
yourImageView.setBackgroundResource(R.drawable.you_background_image_asset)
Related
I wonder how can I create such a background in Android as shown on the image below:
I know how to create gradient background and I found out how to use patterns but how can I combine both of them?
Check these out
http://mdswanson.com/blog/2012/01/30/repeating-background-textures-in-android.html
Android: how to create a background from pattern?
I am trying to beautify some of the UI components in Android. I need to create a button with black border and background color. Everything is fine if I hardcode the variables into XML. But i have different buttons with different background color and different border color and size and etc. all the variations you could say. And it is surely wrong if I go and create all the variations in separate XML files. At the moment, I am creating styles in code but it looks a little inefficient.
gradient.setColor(getContext().getResources().getColor(R.color.ORANGE));
gradient.setCornerRadius(5);
gradient.setStroke(5, 0xFF000000);
button.setBackground(gradient);
And if I want to have button with different background color, I need to create another gradient and initialize it and set to button's resource. Another thing, when I am setting the background of the button, I am also losing the color change when the button is pressed. How do you create an XML drawable resource that can be customized in the interface? Or what is the easier way?
Thanks.
used this:-
Drawable mDrawable = ContextCompat.getDrawable(youContext, R.drawable.youdrawable)
mDrawable.setColorFilter(PorterDuffColorFilter(youColor, PorterDuff.Mode.MULTIPLY)
button.setbackground(mDrawable)
How to create a button as shown in the picture:
and also Image name Button should permanently change color on click. Moreover I will be creating this button dynamically from the android file. So it will be good if somebody suggest me in that way instead of xml files way.
Have a look at the ImageButton class. You can easily create this at runtime so long as you have the picture file for your button in your resources. For it to permanently change colour simply create the different coloured version of the file, put that in your resources folder too and run some code on the onClick of the button to change the image of the ImageButton to the different coloured image. Should take no more than a few lines of code.
See: https://developer.android.com/reference/android/widget/ImageButton.html
is there some way how to access android system private drawable: ic_btn_round_more?
This is the more icon which is used
in DialogPreference (res.layout.preference_dialog.xml)
It's not accessible through android.R.drawable
I don't want to copy bitmap file, because
that icon can be different for every device.
I found this: http://www.androidjavadoc.com/2.3/android/R.attr.html#moreIcon But I'm not sure how can I use it. Basically I'm trying to add more icon to my custom ListView,
which whould look exactly android way.
You can use Nine-patch to create your own rounded button which can be exactly the same as drawable ic_btn_round_more. you can get more information about how to use Nine-Patch here : http://developer.android.com/guide/developing/tools/draw9patch.html
I have a listview in which i have an image and text content getting populated from the java code.
I'm unable to get the default orange selector working on the image. The image is placed ontop of button as setBackgroundResource() from Java.
Can anyone help me with the same?
you could do change background by using drawable property of button in xml file. if you will use this setbackgroundresource() then it will ruin the effect of clicking on it. if u still want to use image as background source then u should create selector xml file for the button background.