I have a listbox with a custom background. It displays a thin white line on either side with a black background. Works great on all my test phones (Galaxy Captivate, Vibrant, Nexus 1, G Tablet, Archos 32, Droid). I just got a Droid 3 to test on, and on this one phone, the background of the listview where there are no items is grey. The list items have the correct black background.
Here's the layout containing the list view. The listview has white background text box above and below, and the background for the listview is the drawable (I know it's called a three border, but it's only a two border).
<RelativeLayout
android:layout_below="#id/divider01"
android:layout_above="#id/save_current_button"
android:id="#+id/profile_middle_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="3dip"
android:orientation="vertical">
<TextView android:id="#+id/user_profile_row"
android:text="#string/user_profiles_label"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#android:color/black"
android:background="#drawable/roundedtop"/>
<TextView android:id="#+id/current_profile_name"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#2B497B"
android:background="#drawable/roundedbottom"/>
<ListView android:id="#id/android:list"
android:layout_below="#id/user_profile_row"
android:layout_above="#id/current_profile_name"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="3dip"
android:paddingRight="3dip"
android:drawSelectorOnTop="false"
android:background="#drawable/three_side_border"
android:cacheColorHint="#ffffffff"/>
</RelativeLayout>
Here's the drawable - this should force the background to black.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFFFF" />
</shape>
</item>
<item android:left="3dp" android:right="3dp">
<shape android:shape="rectangle">
<solid android:color="#FF000000" />
</shape>
</item>
</layer-list>
I noticed that in my list item xml, I don't have the alpha layer specified in my colors, so I tried taking off the leading FF on my drawable, but it came out the same.
Anyone have any ideas where I can look to fix this? It looks really ugly on a nice phone.
Thanks,
Greg
A buddy found a comment on a Motorola forum:
Motorola changed attribute values for built-in themes on Moto devices
with 2.3. "If you set overScrollFooter to #null, the bottom-of-list
background becomes transparent and your background image shows
through.... If you want a bottom-of-list background, but a different
one, you can set overScrollFooter to a color or drawable..."
android:overScrollFooter="#aa000000"
android:overScrollFooter="#drawable/my_drawable"
http://community.developer.motorola.com/t5/MOTODEV-Blog/Why-Does-My-ListView-Look-Different/ba-p/17462
I'm still not entirely sure what they are doing when rendering this space, but I can get it to work. If I use the drawable option, and give it my drawable with the left and right borders, that object gets drawn inside the border from the listview background - i.e. it is somehow still showing the first item in my two-layer background drawable, so the space below my list items now has a wider border, but it is black. This is at least consistent with my earlier test when I changed the first layer to blue, and got a blue line the entire height of the listview. If I just go with a straight black #ff000000, then the listview looks the same as all my other phones. So I'm not sure how they are calculating the footer space - I don't see how they would know that I have a two-layer object and just be replacing the second layer. Something else must be going on that I just don't understand, but it does work.
There was a also a comment that you would need to select a theme based on the android version, but so far in my testing all the platforms take the new tag without complaining.
Related
Here's the XAML that I am using for a startup screen:
<?xml version="1.0" encoding="UTF-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<item android:drawable="#android:color/black"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test"
android:gravity="center"
android:layout_gravity="center"
android:textSize="40sp"
android:textStyle="bold"
android:fontFamily="sans-serif-medium"
android:textColor="#fff"
/>
</layer-list>
I was hoping to see white text centered on a black screen. The screen is black, but instead I cannot see any text appear at all.
I understand what you are trying to do.
You want to display a plain Text on your "Splash Screen" that displays when you open an app. Since you are using Xamarin, you have access to all the native API's and you can do everything that native developers can.
Unfortunately, being able to show plain text on the splash screen is not possible in native development. Android restricted it because "the view comes from the theme. When you set up the UI for your splash activity in the theme, it is available immediately".
Why can't I have plain text on the splash screen, when I can have images? As you see over here in detail, the splash screen only accepts drawable resources. And there is no way to convert plain text into XML drawable resources.
You do have another option though. You can use a "Loading screen". You can make the app show the splash screen, then a Loading screen, and then load the right page. Let me know if that makes sense
Set background attribute to black. Either
android:background="#000"
or
android:background="#android:color/black"
I'm not used to Xamarin in specific, but if you normally want to create some sort of splash screen for your activity, as far as I know, there is no way of directly adding a TextView to it, because LayerList only supports bitmaps (image drawables) as child items. So you would have to create an .img file containing your text. Then, you can add the image with the text to the layer-list like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This line below is for the background colour -->
<item android:drawable="#000" />
<item>
<!-- The bitmap below contains the image with the text -->
<bitmap
android:src="#drawable/my_text_on_screen"
android:gravity="center" />
</item>
</layer-list>
To see how to create an image from a text, have a look at this StackOverflow question.
Let me know of this is what you wanted to achieve! I hope this helps.
I have two buttons, one of them has default style, another has custom background drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="4dp" />
<solid android:color="#color/green" />
</shape>
In the end buttons look like this:
So default button is somehow smaller than button with custom background, though they have same properties:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/bg_button_rounded_green"
android:text="Positive"
android:textColor="#color/white"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Negative"/>
It seems that custom background changes minHeight. How can I make this buttons look the same?
btn_default_normal.9.png is the default Image set to default Button widget in Android from any specific platform. Find this file in you SDK installation and copy to your res folder.
Path to find android-sdk\platforms\android-APILEVEL\data\res
Default button have default 9-patch background with own margins, shadows, etc (different for different Android versions). You have to use custom background for both buttons or take one of the default 9-patch background and create similar bg for positive button.
The default Holo Android button graphic is a PNG which purposely contains padding. If you press and hold, you'll notice a glow around the button appears...which takes up that spacing.
The default 9 patch image for the button uses drawable padding. In order to mimic it in your own drawable you can use insets. Something like:
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/bg_button_rounded_green" android:insetBottom="10dip"
android:insetLeft="10dip" android:insetRight="10dip" android:insetTop="10dip" />
I'll let you figure out what the values should be.
I have an activity with a coloured background and a button which is the same colour which I want to minimally show with a white outline.
I used this answer to make a border on a button and it works just fine for me on Nexus 4 and 5 running 4.4.4
I try it on a Samsung S2 running 4.0.3 and the entire button turns black. No border. The button should be same colour as the activity with a white border. Text colour on the button (white) is just fine
Here is my border.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="3dp" />
<stroke
android:width="1px"
android:color="#ffffff" />
</shape>
Can anyone explain the different behaviour, and more importantly tell me how to fix it?
Thanks
Edit
Well I don't have a real answer, but I think I'm going to fix it by adding in
<solid android:color="#color/mycolor" />
To my drawable shape. I think this works, but it's not very elegant if I want to have a transparent background. I may try setting the color to transparent at some point (on the assumption that some phones/versions of Android default to a black background and this is that easy to change), but no time for it now.
I am having trouble customizing the look of an Android Switch widget. I have custom xml drawables that I want to use for the thumb (the little button part that usually says On or Off) and the track (the background that the thumb slides across). When I set just the thumb using android:thumb, it works fine. When I set the track (whether or not the thumb is set), the switch disappears entirely and I'm left with only the text showing.
Here is my code when just the thumb is applied:
<com.blahblahblah.blah.CustomSwitch
android:id="#+id/switch_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="Off"
android:textOn="On"
android:text="Something Awesome"
android:textColor="#android:color/black"
android:thumb="#drawable/custom_switch_thumb" />
Here is what it looks like in the preview window:
And with the track applied:
<com.blahblahblah.blah.CustomSwitch
android:id="#+id/switch_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="Off"
android:textOn="On"
android:text="Something Awesome"
android:textColor="#android:color/black"
android:track="#color/track_color" />
Preview window with track applied:
For reference I am using Android Studio 0.2.3 on OSX 10.7.5.
I just stumbled upon the same problem and found a fix through on the HoloEverywhere issue tracker. You'll need to set the <size> of the drawable XML shape you are using.
Not working (the widget is there and I can interact with it, but I can't see it, it's hidden):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/black_50" />
</shape>
Working (not the added <size>):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/black_50" />
<size android:width="56dp" android:height="20dp" />
</shape>
In general just for changing an image you don't need to subclass a control you can style it e.g. with the style attribute.
About your problem there are several controls which expect a drawable and not a plain color. In the control definition (the xml part) you can just define that you allow a reference but you cannot limit it to drawable references. So just avoid to use colors directly. If you don't want to add a image you could also define it with xml, but note that this does not work in all cases.
I'm struggling with a small problem, my question is I am using a transparent edit text view in the design part, in 4.2 version android device looking fine well and good, if I check that same edit text in 2.3 version and below version showing a black coloured edit text. this is my edit text code.
<EditText android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dip"
android:layout_weight="1"
android:alpha="0.3"
android:background="#drawable/reg_edittext"
android:ellipsize="end"
android:ems="10"
android:lines="1"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#ffffff" />
here is my reg_edittext
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:padding="10dp" >
<solid android:color="#000000" />
<corners android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
showing a black coloured edit text in 2.3 version, in 4.2 showing transparent. answer me I would like to view same transparent in 2.3 version
Although #Sri's answer is mostly correct, it's not complete. You're seeing an opaque black background because the following attribute wasn't added until API level 11 (Android 3.0):
android:alpha="0.3"
Fortunately, you can add transparency to colors. To make the background color translucent, with the same 0.3/30% alpha value, change the solid declaration to:
<solid android:color="#4C000000" />
please check the link
android:alpha="0.3" this alpha property is added in API level 14. So in the previous version it map looks different depends on devices.
Try to change the backgroud solid color as transparent it may help you out.
android:color="#000000" to transparent color range- #FF000000 to #00000000
You must specify alpha also while specifying the color if you want to give any transparency for the same. So the total color value should be in the format #AARRGGBB where AA - is the alpha color value (00 - transperant, FF- opaque) , RR - red color, GG - green color, BB- Blue color. In your case to get complete transperant background gou have to specify like this:
android:textColor="#00000000"