I have a issue with my listview, I basicly want the text in the fields (in the listview) to become black instead of white as default. I've followed a simple guide how manage this but it is not working for me. This is the guide: http://www.hascode.com/2011/12/writing-styles-and-themes-on-android/ .
This is my style.xml file were I try to enter a dark color to the text:
<style name="CustomTextView" parent="#android:style/Widget.TextView">
<item name="android:typeface">monospace</item>
<item name="android:textColor">#000000</item>
</style>
This is my bookmarks.xml were I try to load the style in the listview with following code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/CustomTextView">
</ListView>
</LinearLayout>
I've also tried to change the parent name in the style.xml to TextAppearance.Medium instead, but nothing works. Am I missing smomething, why canĀ“t I just change the damn color? Please help! Thanx!
you should set the style="#style/CustomTextView" to the UI element that represent your listview's row (the TextView where you will put the text, eg)
ListView is a kind of container... Inside list view you add the views.. in your case you are adding TextViews... so you should set the style of that TextView which you are adding to this ListView...
Related
I have define a theme for an activity and the background color here is #67b4ef.
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">100dip</item>
<item name="android:background">#67b4ef</item>
<item name="android:textColor">#ffffff</item>
<item name="android:textSize">20dip</item>
</style>
this activity has a listview that should be white and I set background for it as:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:background="#ffffff">
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:divider="#null"
android:dividerHeight="0dip"
android:focusable="false"
android:focusableInTouchMode="false" >
</ListView>
</LinearLayout>
but the color of list-view is affected by color of theme background. I don't want this.
listview:
lv=(ListView) findViewById(R.id.listView1);
This problem happen because you are using default android Adapter .....
Use Custom Adapter and change the List item color
Use this link Custom ListView
If you stuck anywhere in between Custom ListView ask here in comment.
enjoy coding.......
Instead of setting ListView's background to #ffffff, you should set the background of each item in the Listview to #ffffff.
What happens with your original approach is your ListView background is #ffffff. However, all the item views on the ListView have the default background from the theme (#67b4ef). As a result, the background you see on the screen is the theme background.
I am trying to achieve a simple thing instead of always setting the parent layout background to be null, have it null by default with by changing the application theme.
It should look something like the following style:
<style name="MyViewGroupsStyle" parent="android:Widget.ViewGroup">
<item name="android:background">#null</item>
</style>
And have my main theme include it
How do I achieve that?
The result should be like the follows:
<?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:orientation="vertical"
android:background="#null" >
</LinearLayout>
But without adding a style attribute to every layout(view group).
I want to change the title bar color .Following the instructions here
, or eliminating the title bar with Notitle bar in AndroidManifest esults in not showing the text fonts in the list view (I use "simple_list_item_checked" listview).
Here is the xml for this activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FFFAFA"
>
<Button
android:id="#+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/green_button"
android:text="#string/show_items_kfc"
android:onClick="onClick"/>
<ListView
android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
(the rest of xml code is the same as the link above)
Any solutions to this?
Thanks!
If I got the problem:
Instead of parent="android:Theme":
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
</resources>
Use parent="android:Theme.Light":
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="customTheme" parent="android:Theme.Light">
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
</resources>
The problem is that you are overriding the native Black theme which has black background and white letters. By switching to Light theme you achieve the black letter also have your own white background!
Note: After that you may have to fix custom theme colors (eg. title text color force to white) to white/black if they do not fit the UI you need.
you can use the titlebar object for the purpose...
the link below gives the good explanation on how to do that...
Title bar color change issues
I am using ListView inside a ViewFlipper as follows:
<ViewFlipper
android:id="#+Category/viewFlipper"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:entries="#array/options"
android:cacheColorHint="#FFFFFF"
android:background="#FFFFFF"/>
</ViewFlipper>
I want to change the background color of the ListView.
I have only 5 items in the options array and they do not fill the screen. So, the remaining part of the listView appears in the default grey color. I want to change this default color. I read about cacheColorHint attribute in questions posted by others related to this. But it did not work out. Can anyone please help me with this?
Thanks in advance
You should use layout_height="wrap_content" (and layout_width="wrap_content" also if need) for your ListView and change the "default grey color" like you said by set the background for ViewFlipper.
Set a selector as the background of your ListView:
ListView mylw = findViewById(R.id.mylistView);
//Do not use reserved android or java identifiers as your id or variable!
mylw.setBackgroundResource(R.drawable.thexmlbelow);
Drawable:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="Background Color" />
<item android:drawable="Background Color when pressed" />
</selector>
Any idea why this doesn't create an activity that looks like a popup instead of an activity that completely fills the screen?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="300dip"
android:layout_height="120dip"
android:layout_marginTop="100dip">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="120dip"
android:layout_width="300dip">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
</RelativeLayout>
</LinearLayout>
I assumed that I only needed to set the layout height and layout width to something other than "fill_parent", but it still shows up as a black screen that completely fills the screen.
Ultimately, I simply want to create a popup, but I do not want to use an AlertDialog. Is this possible?
You must set your Activity's window to be floating. You can do this either by giving your activity the Dialog style defined by Android (android:style/Theme.Dialog), or define your own style, like this:
<style name="MyFloatingWindow">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
</style>
Then set the style on your activity in the application's Manifest.
On my phone but check this website here it shows how to use PopupWindow correctly.
Hope this helps or points you in the right direction.