Android drawable background doesn't show on devices - android

I want to give to a TextView a background. This background (classement_background.xml) is a drawable located in res/drawable.
Here's its code :
<?xml version="1.0" encoding="utf-8"?>
<shape
android:shape="ring"
xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:startColor="#ff648add"
android:endColor="#ff3656dd"
android:type="linear"
/>
</shape>
In the render window of the layout file, my background is set. (Android studio)
But for some reason, this drawable is not there anymore on a genymotion emulator nor an actual device.
I've been trying quite a few things (like making sure it isn't the first element in the drawable folder), but I can't figure out what's going on. Any thoughts ?
Here's the code from the textview itself : `
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E2"
android:id="#+id/classement"
android:layout_below="#+id/firstname"
android:layout_centerHorizontal="true"
android:textSize="85dp"
android:layout_marginTop="15dp"
android:padding="30dp"
android:background="#drawable/classement_background"
android:textColor="#android:color/white"/>`

Add the android:useLevel="false" attribute to your shape tag. My IDE didn't display your shape in its preview window until I added it.
According to the docs:
android:useLevel
Boolean. "true" if this is used as a LevelListDrawable. This should normally be "false" or your shape may not appear.

Try to set android:thickness for the shape. Maybe android doesn't provide a default thickness for the xml drawables.

Maybe I will post something, that helped me.
My backgroung id 1920x1920 pixels and display 1920x1080, so different size shouldn't be the problem.
I suppose that you have your background putted in some resource "drawable" folder (for example in drawable-hdpi) in Eclipse IDE. I had that either and on real device (Sony Xperia Z2) I haven't seen nothing.
Short answer:
I had to add my desired backgroung to every single drawable folder - drawable-ldpi, drawable-xxhdpi, ...
After this strange operation Sony finally recognized my backroung and accepted it. :-)
I hope this will help somebody.

Related

Increasing size of bitmap image in splash screen

I am creating a splash screen for android using drawable xml, and my
back_splash.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#android:color/white"/>
<item>
<bitmap android:gravity="center" android:src="#drawable/ic_launcher"/>
</item>
</layer-list>
Now the Issue is if I keep android:gravity="center" in bitmap, it makes my image too small for all devices.
If I keep this property in item it makes image ok for small phones but make it horrible for tabs.
I have tried everything, like using mimap (where I have all sizes of image) , using drawable where I have kept different sizes of nine patch image, but nothing seems to make the image look good.
(I have created ninepatch image using an online tool)
Now as keeping android:gravity="center" makes it just small (not blur), I want to know if I can increase this image size a bit more, using any work around?
I have wasted a lot of time to make it work, but nothing useful.
Thank you all in advance
This worked for me:
<item android:gravity="center">
<bitmap android:src="#drawable/ic_launcher"
android:gravity="center"/>
</item>

Delphi XE7 Android splash screen - background color

I can see Delphi XE7 comes with splash/startup image support for Android.
However, when I choose to center the image (which looks best) Delphi shows black color around it. I would prefer white since it fits better with the image and color theme of the app. There does no appear to be an opion for background color where you set splash/startup images.
How can I change this color?
If you want fill the black background with the same background color from your image you must use 9patch images. To make 9patch pngs use NinePatch (included in android sdk)
Once you hace the images, add to your project and set up like this:
splash tile mode: disabled
splash gravity: center
Then go to project -> deployment:
Uncheck splash_image_def.xml (to not deploy)
rename your splash_image.png to splash_image_def.9.png
If you are just wanting to change the background color of the splash screen, you can modify two files. colors.xml and splash_image_def.xml. You will find these in the Android/Debug/ (or Android64/Debug/) folder of your project. These get recreated each time you deploy your application so you will need to make backup copies of them.
In Project|Deployment, untick these items and create new entries for the copies you have made, making sure that you deploy them to the same location. You will end up with two entries for Debug and Release.
Edit colors.xml and add the new color that you want like so
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<color name="notification_accent_color">#000000</color>
<color name="logoblue">#0094ff</color>
</resources>
Here I've added the logoblue color. Next edit splash_image_def.xml and change #android:color/black to #color/logoblue. It should look somewhat like the following
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item android:drawable="#color/logoblue" />
<item>
<bitmap
android:src="#drawable/splash_image"
android:antialias="true"
android:dither="true"
android:filter="true"
android:gravity="center"
android:tileMode="disabled"/>
</item>
</layer-list>
There might be a simpler way of doing this, but this is what I've come up with through a bit of trial and error.
There is no background color property of splash images because this is supposed to be a part of the image. There are 4 different possible sizes for Splash Images on Android:
426 x 320
470 x 320
640 x 480
960 x 720
So, depending on your supported devices, you should have up to 4 images matching these sizes, with the background color being whatever you wish. Set it up to fill the entire screen, and make sure you're not using transparency. For Splash Gravity, select the fill option.
to change default black splashscreen, just open
splash_image_def.xml at debug folder,
and change "black" to white if you want change it to white, like this
<item android:drawable="#android:color/white" />
Note : Build it with no change at source code, layout or anything at RAD Studios. Just edit the file xml with notepad, save it, then rebuild.

How to use Nine-patch images correctly

I want to create some kind of row image that looks like that
but I want it to scale with the screen size and density. So reading this http://developer.android.com/guide/developing/tools/draw9patch.html and this http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch I startet creating a Nine-patch image.
But when I import it and use it in my android project it looks like that
As you can see the little black line that was drawn with the draw 9 patch tool is still visible. Why?
Here is the 9.png image
Are you using the draw9patch tool that comes with the sdk? it is quite handy.
Anyway:
It is vital that every pixel except the black ones are completely
transparent.
The black pixels should be at the absolute top/bottom/left/right of
the image.
The image should be named filename.9.png.
I have found the best and the simplest answer to make 9-patch image.
This is best link to create 9-patch image for all the resolutions - XHDPI, HDPI, MDPI, LDPI in just one click.
Let me know if you have any queries, and do upvote it, if it was helpful to you.
If you need an image which consists of a border with rounded corners, I don't have to create a 9-patch.
All you need is an XML like this stored in the res/drawable directory
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="3.0dp" />
<stroke
android:width="2dp"
android:color="#color/green" />
</shape>
Read more about drawable resources

Android. Avoid scaling of background

In a start activity of our android application we're using a linearlayout with an background image for whole space.
The image size is 320x480 - the same as device resolution, we're using for testing.
The problem is, the image will be scaled und looks not so nice.
I tried to use imageview instead, but I've got black borders.
Some ideas, how to avoid scaling or how to get the proper size for background image?!
Thank you in advance.
Mur.
Create a background.xml file in res/drawable and use the following:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background_image"
android:gravity="center"/>
And use this background.xml as your LinearLayout's background.

Android view dithering

As you can see from the screenshot below, the "titlebar" is getting these ugly banding lines across the areas with text that extend the entire width of the screen. It's even more noticeable on a real device.
Is there any way to work around this?
From Android Developers: Widget Design Guidelines:
In some cases, devices have low pixel
depths that can cause visual banding
and dithering issues. To solve this,
application developers should pass
assets through a "proxy" drawable
defined as XML:. This technique
references the original artwork, in
this case "background.9.png", and
instructs the device to dither it as
needed.
EDIT:
Example source. This is an xml file in your res/drawables directory:
<?xml version="1.0" encoding="UTF-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/title_bar_medium"
android:dither="true" />
Add android:tileMode="repeat" in this code, like this -
<?xml version="1.0" encoding="UTF-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/b1"
android:tileMode="repeat"
android:dither="true" />
Reason is, on some devices it still stretches the image and it looks pretty bad, check this
Reference here

Categories

Resources