android -How to make background like this - android

I need to make background like this for each row on my listview .
Is there anyway to do it without using background images ? I mean is there anyway to make this by just using xml drawables ?
thanks

You need to create a repeatable Bitmap and set it to your layout as a background.
Use this image
(You can edit image if you want to change color etc , if you need psd file i can share)
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/rep_bg"
android:tileMode="repeat" />
in your layout set
android:background="#drawable/backrepeat"
Final output would be

Related

Android TextView BG opacity?

I want to change the opacity of my bg in my textview, not the text only.
How to do this?
As I mentioned, it's not a duplicate question, because I don't want to change my textview opacity, i want to change my tv bg opacity, so it's a different question.
I have an image behind my text, that I want to change.
Thanks!
One possibility its applicate alpha to image in Photoshop or something similar.
Another possibility its define image in xml source, and applicate this image to edittext background across style.xml Something like this:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/your_drawble"
android:alpha="77">
</bitmap>
Another possibility its use this (values between 0-255):
textView.getBackground().setAlpha(51);

Progress bar using Drawables

I need to create a simple progress bar using two drawable images.
One is the background of course.
The other I need to scale according to a percentage float.
Is it possible using Java code only? I tried the setBounds() method with no avail... :(
thanks
You can perfectly and easily do that using only XML code.
First, in the layout of your activity specify the XML in where you declare the style of the progressbar, in this case #drawable/custom_progressbar:
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:progressDrawable="#drawable/custom_progressbar"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:background="#drawable/progress_bar_background" >
</ProgressBar>
Then, in #drawable/custom_progressbar declare that the progress will be expressed with a bitmap that clips according to the progress. The id is important as it is used by Android's ProgressBar widget.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#android:id/progress">
<clip>
<bitmap android:src="#drawable/progress_bar_foreground" />
</clip>
</item>
</layer-list>
Then, in the declaration of the progress bat in the layout specify the background of the progressbar.
The background should be specified in theory in the progressbar layer list with the id android:id="#android:id/background, but it didn't work for me in this case. I think Android designers thought of that to be used as a stretchable 9patch or a tiled bitmap. I wanted to do the same as you and I only got it by declaring the background as usually in the view in the layout.
Hope that helps.
As I am sure you are aware, custom elements in Android take a significant amount of effort compared to the pre-compiled api's. If I were to do something like this, I'd create a custom class that extends View, and scale my progress image bitmap or canvas inside onDraw() method. And call PostInvalidate() for each time I need to update it. However, generally custom progress bars are done a bit differently in Android. Instead of scaling the progress drawable it simply reveals a portion of it depending on the percentage.
To get an idea on how to do a custom progressbar take a look at this.

How to give the library background as Aldiko Android App to Grid View in android?

I have to give library background for our gridview in our Android App. Because I am making an App just like a library. How to achieve the same? Please suggest me regarding the same.
For providing library background for the gridview, create the backgroud image as you want and set as as the background for the gridview.
you can set background in xml file as well as in code
for xml file add attribute in the GridView tag as( suppose your image file name is mybackground)
<GridView android:backgorund="#drawable/mybackground" />
for the code
GridView gv=(GridView)findViewById(R.drawable.myGridView);
gv.setBackgroundResource(R.drawable.mybackground)

Android white image is not white when minSdkVersion="10" [duplicate]

This question already has answers here:
Image does not show completely white despite it's correctly white
(6 answers)
Closed 7 years ago.
I have an ImageView in Layout. Layaout background is white (#android:color/white) and in ImageView contain a *.png picture. But white color on this picture is not the same white as in layout it is little gray.a http://desmond.imageshack.us/Himg513/scaled.php?server=513&filename=1325684647707.jpg&res=medium
I tried to change the format of the file, different color depth etc but it doesn't help. Then I remove minSdkVersion from manifest and it solve the problem. But I really need this tag in manifest. Does anybody have any idea which format of picture or what I have to change to fix it?
Thanks a lot
I have answered a similar quention: Image does not show completely white despite it's correctly white
Copied from there:
The cause of the problem is that regardless of the original bitmap format in the APK files all bitmaps are compressed (in my case into indexed 256-color! wtf?).
I couldn't find the way to prevent it, so if anyone knows the proper solution, please tell.
However, I found two solutions for the white color problem.
1) Per-bitmap: Say, we have a drawable bitmap resource called #drawable/mypng, which causes the problem. We need to add an additional XML drawable drawable/mypng_nofilter.xml
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/mypng"
android:filter="false"
/>
and use #drawable/mypng_nofilter instead.
2) For entire activity: In activity onCreate method we need to add
getWindow().setFormat(PixelFormat.RGB_565);
Now the window has 16-bit color depth and all bitmaps appear "properly" white.
Again, I would prefer to have 32-bit color depth, but I don't know how to control compile-time image compression.
instead of using default white color. redefine the white color in you xml and use the same
Create colors.xml under res-> value
<?xml version="1.0" encoding="utf-8"?>
<resources><color name="white">#ffffff</color> </resources>
Use this white color in you xml by #color/white" example android:background="#color/white"

Setting a picture for button i made in XML (Android)?

I'm having this question about setting pictures for Buttons in XML :
I made some .png pictures I want to set as pictures instead of the buttons that I get in default when i create my android apps.. Now I loaded in the files into the drawable folder.. And how do I write in XML to get the right thing?
Is setting the button visible to false and adding a picture as background for it an option?
Because that's all the ways I thought about. Or is there a better way to do this kind of thing?
what I understood is that you want to set the picture in background. Do it like this in your Button tag:
android:background="#drawable/yourpicturename"
Add the png to the drawable folder that is under the res folder in your project (if you are using eclipse). Then in your XML file simply use android:background="#drawable/filename". Make sure to omit the file extension
You can use any of:
drawableTop, drawableLeft, drawableRight, drawableBottom
For example,
<Button android:drawableRight="#drawable/some_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Some text" />
The image some_image.png will be positioned to the right of your text in this case.

Categories

Resources