I am trying to change the background of whole screen to white. I doing it by adding by android:background="#ffffff" attribute to linerlayout. but it is not working, i dont know what i am missing ?
http://developer.android.com/reference/android/widget/LinearLayout.html
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:padding="10dip"
android:layout_width="fill_parent" android:layout_height="wrap_content"
**android:background="#ffffff"** >
I also tried to this programtically , something like this
setContentView(R.layout.main);
LinearLayout linLay = (LinearLayout) findViewById(R.layout.main);
linLay.setBackgroundColor(Color.WHITE);
but application throws error
Are you please able to post the complete code necessary to replicate your problem?
This works fine for me:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF">
android:layout_height="fill_parent"
also setBackGroundColor(int) takes a #color resource , not a color integer. you declare them in values/colors.xml
Related
For a long time I am reading posts from stackoverflow because they are very helpful and google seems to think that also.
Since yesterday I have a problem with a row in a ListView in Android. I want to show an image and the area between the image and the bottom of the element should be filled with a grey color.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/ConversationsBadgeLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#c0c0c0"
android:orientation="vertical" >
<QuickContactBadge
android:id="#+id/ConversationsBadge"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
<!--
...
A LinearLayout with TextViews, shouldn't be interesting for this
...
-->
</RelativeLayout>
My Problem ist that the it seems that the inner layout only wraps the content but doesn't fill_parent. When I set for example 100dp it works but that is not what i want.
It would be nice if you could help me with that. I tried much workarround like using LinearLayouts and TextViews but nothing worked.
You can set the background color to the ListView itself, then everything in it will have the background you want.
BTW, I recommend using LinearLayout instead of RelativeLayout in your case.
The layout file should contain exactly one outermost element and it should have both android:layout_width="match_parent" and android:layout_height="match_parent" Your RelativeLayout has android:layout_height="wrap_content"
i think you can use you can take background color in another xml file and put in drawable folder and also using Linear Layout is very useful to your problem
I'm trying to create an achartengine chart within a scrollview but it won't display! It just shows a black screen, but doesn't crash or anything. The thing is if I just change my tag to the chart displays just fine. And in my Java code I do have renderer.setInScroll(true); for the charts renderer. Is this an issue with my xml?
Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/trendchart"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</LinearLayout>
</ScrollView>
(Currently the only thing in the ScrollView is the chart I plan to add more elements to make scrolling necessary, I just want it to display first)
Also I have tried to display it both with and without the wrapping linearlayout and it is the same result.
Under the scrollview you have to insert
android:fillViewport="true"
You will also have to do the following call, otherwise there will be display issues:
renderer.setInScroll(true);
Other solution is to give a size for your LinearLayout #+id/trendchart:
for example:
<LinearLayout
android:id="#+id/trendchart"
android:layout_width="fill_parent"
android:layout_height="180dp"
android:orientation="vertical" />
</LinearLayout>
works fine for me.
I've tried the accepted answers but none of them work for me. I solved my problem by adding
chartView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 500));
But don't use
chartView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
because for some reason it still not displaying the chart. Hope that will help someone
I have a problem with getting the background to display in the emulator. It will show up on main.xml though and there is no errors. So the screen just comes up black here is my main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background = "#drawable/clearskies">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
</LinearLayout>
and yes I do have my image in the drawable folder and the spelling is correct and the image is a .png
Can anyone see what im doing wrong here?
Thanks
Check if you are setting the layout file.
in onCreate(), use,
setContentView(R.layout.main);
Can you see your image in background of graphical Layout of your xml if yes then it must problem with your java file otherwise it problem with your image or drawable something else...
Hi I cant figure for the life of me to change the background of this to white.
CODE:
<?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:background="#FFFFFF"
>
<ExpandableListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
>
</ExpandableListView>
</LinearLayout>
Make the black here white
Probably going have to change the font color to black.
Can you post a screenshot of how it looks now? And perhaps a quick description of how you'd like it to look?
Does it look like you want it to but mess up when you go to scroll the list?
Check out this page for some useful info on using listviews with custom backgrounds: http://developer.android.com/resources/articles/listview-backgrounds.html
try setting the cacheColorHint:"00000000"
I am trying to create a widget that displays items parsed form an XML file file. In the end, an image, a title, and URL of the original item are going to be displayed. But, now that I am working on the layout, I am getting a runtime error after adding the ImageView to its container. The <RelativeLayout android:id="#+id/newsdviewlayout" is inside the root View (which is a RelativeLayout) for the main layout. Help please.
<RelativeLayout
android:id="#+id/newsdviewlayout"
style="#style/newsviewstyle"
android:layout_alignParentBottom="true">
<ImageView
android:id="#+id/newsviewimg" />
</RelativeLayout>
Yeah, I think you miss the required attribute android:layout_width="" and android:layout_height="", so for your case, the xml will be like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/newsdviewlayout"
style="#style/newsviewstyle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">
<ImageView
android:id="#+id/newsviewimg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Or as for the RelativeLayout you can also put that 2 attribute inside your newsviewstyle style.
You have to give the android:layout_width and android:layout_height for both RelativeLayout as well as the ImageView.