Ok I have created a background image in Inkscape. Exported that image and it looks correct, when I open it from Eclipse. However, when I build the project and apply that background to the Layout, it shows the complete opposite in the designer and on the device.
Here is what the image is supposed to look like. Correct background
Here is what the image looks like in the Eclipse Designer.Incorrect background.
Here is my Xml on a brand new Xml file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/list_view_bg"
android:orientation="vertical" >
</LinearLayout>
I am utterly confused on this one. Any help is greatly appreciated.
You are most likely using a theme where the background in dark. As your background gradient is transparent the black background is showing through.
Switch to a light theme.
Related
After trying just about everything, I cannot get the color preview to show in the XML editor in Android Studio. In my colors.xml file, I expect a line like <color name="colorAccent">#1AD270</color> to show a small square to the left of it in the gutter previewing the color.
Weirdly, it only happens in this particular project. When I open other Android Studio projects, the gutter icons appear normally.
I have completely reset my Android Studio settings, disabled/enabled gutter icons and changed the gutter background, none of which worked. Any help?
Turns out that the color previews do not show up if you don't have an activity in your project. After adding the first activity, the color preview icons suddenly appear. Weird!
Just to expand on zwh's comment, you bizarrely need to have a layout xml in the layout folder of the module.
It doesn't need to be linked to an activity at all, or mentioned anywhere, just has to exist! I created one called dummy_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- If this file is deleted, colors.xml doesn't show colour gutter icons https://stackoverflow.com/a/65395717/608312 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" />
I have a Splash Screen with a background Image on top of it. I have a Video View which plays the video. The background of the video and that of the rest of the screen must match, hence I extracted the background color from the video and added a background image of the same color in the XML file.
The problem is, the color of the image does not match with the video on all versions of Android.
On Sony Xperia SP with v4.3:
On Micromax A1 with v6.0.1:
How do I get consistent result across all (or most) versions of Android?
XML of Splash Screen:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/logoback"
>
<VideoView android:id="#+id/myvideo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
</RelativeLayout>
Instead of using drawable for setting the background, extract the colour code and set the colour code to background. It might resolve the issue.
Question: Is there a way to dynamically set the "src" attribute on an XML "bitmap" in an Android XML file?
I have a custom XML drawable named "repeat_background.xml" defined as such:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background"
android:tileMode="repeat" />
I use this drawable to "tile" a 1x1 jpg (named background.jpg) as the background for all the pages in my app, and it works great - here's an example setting it as the background of a LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/repeat_background">
However, I want the actual jpg (in this case "background.jpg" from #drawable/background) to be based on the user's preference - so I'll have a list that allows the user to pick red, blue, orange, etc. so the user can override the background color shown in the app, and I'll have a 1x1 jpg corresponding to each available color in my resource bundle - but how do I show the preferred jpg as the background?
I don't want to manually have to call some code in every Fragment or Activity, I want something that will respect the user's preferences and react accordingly.
I've tried to extend the BitmapDrawable class, but didn't get very far. Any suggestions for how I can accomplish this are greatly appreciated.
You can do it in java code, using setBackgroundDrawable(new ColorDrawable(color)). It can't be done in xml.
I'm trying to use the ImageView in Xamarin plug-in for Visual Studio 2012, but when I use png with transparent background like a src I get just black screen.
That's strange but some time ago I could do it, but now I can't. Photo viewer in Visual Studio shows my image just black.
When I run my app on the device I get black screen too.
Here is the XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:src="#drawable/plus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView1" />
</LinearLayout>
Previously, I did not have this problem, I think...
If I use the same image in ImageButton and when I use image without transparent background all ok!
Renaming folders Drawable does not help.
How can I resolve this issue?
this is what i think, your image has a transparent background, already, and you also set the widgets background to transparent, now by default your activity or layout theme, by a wild guess has a background of black..so check this out.. Image has a transparent background and the image is a black image, and your widget has a transparent background which tends to show you the theme's background which is black, so your image fades in, to the background image showing the image but since the image itself opage portion is black you get a black Screen this is a wild guess, so do this.. set your linearLayout background to lets say red or white, and everything is gonna be alright
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:background="#fc9" // red or you could do it #fff white
android:minHeight="25px">
<ImageView
android:src="#drawable/plus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView1" />
</LinearLayout>
Edit: i misread your question, my error was i tot you also specify transparency for the widget so, i admit my error, but my logic still stays, this time being the fact that, your layout theme is black and every widget follows that because you do not specify it, and your image is black, it still shows black ..
Note this is wild guess..ayt so try it.. and let me know
I am currently working on a basic app using eclipse as my IDE. I am currently having trouble setting an image as my background. I was following a tutoral which told me to place my image in the drawable-mdpi folder and name it as icon. I have tried this but it keeps on placing in the andriod icon instead even when i delete the andriod icon image. Is there a better way of doing this?
Thanks
try this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal" android:background="#drawable/background"></LinearLayout>
background is a .png file. with borders draw around it with Nine9Patch.
Hope this helps