I am working on a simple app and I want to change the background image. Right now it's just a plain color. I want to be able to use an image from the web by changing the URL in the Java Code. So what I need to know is how to change this tag from the XML android:background="#FFFFFF" to some image I found at the following website:
You can't link an image from the web directly in the xml declaration of a View. You either download the image and then put it in the drawable folder and reference it like this:
android:background="#drawable/name_of_the_image"
or (in java code) you parse that address, obtain the image and then set it as background in code in your activity.
I think you need the View.setBackgroundDrawable(Drawable d) method.
Related
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)
I want to load a text file in Android with custom size and color just as shown in the website (download the 1.html file). This is a HTML file and I have used WebView to show the file but I want to show using TextView. If I simply copy this in Text file it deletes the custom color and the size. Is there any easy way using Java code like loop or something to make specific lines in Red color and the other in black to make it look like it's shown in HTML File?
https://sites.google.com/site/gurbaniujagar/page1
Thanks in advance
Take a look at this site here, it shows you all you need to know.
http://javatechig.com/2013/04/07/how-to-display-html-in-android-view/
I have edited the spinner image by changing the color of it. Then used the draw9patch.bat tool to create it into a proper 9-patch file, and then renamed it to spinner_updated.9.png, then I placed it into my "res/drawable" folder. So I then checked out this link just to get an idea of implementing a custom spinner:
How to create android spinner without down triangle on the right side of the widget
I tried using lencinhaus & Aleadam ways but when I try to actually use it in my app I keep getting the error:
Failed to convert #android:drawable/spinner_updated into a drawable
Couldn't resolve resource #android:drawable/spinner_updated
What am I doing wrong? What would I do once I have the image I want to use for my spinner to actually get it displaying in the app?
If you are using your own drawable you need to use:
#drawable/spinner_updated
The #android: directs the app to look in Android's built-in resources not your own.
I want to use private drawable from android. for that i have downloade androi-8.jar which contains all the .png imgaes i want to use in my activity. i want use "btn_circle_disable_focused " drawable to the buttton but it shows me error regarding private resource. i want to use it in imageview also.
You should copy desired .png to your project's /drawable folder. you can access it from xml like #*android:drawable/btn_circle_disable_focused but it's not a good idea cause drawable being private means it may be unavailable on some devices.
check this google icon design to download every icon you want.
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