I have a shape defined in a drawable resource this is just textView background with rounded edge.
It actually works just fine, but when I reference the shape :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:padding="10dp">
<solid android:color="#7C5B77"/>
<corners
android:bottomRightRadius="5dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="5dp"/>
</shape>
a snippet from my layout.xml file is here:
<TextView
android:layout_width="wrap_content"
android:text="Select Random Student"
android:textSize="15sp"
android:layout_height="wrap_content"
android:singleLine="true"
android:textColor="#E1E7DF"
android:background="#drawable/round_edittext_bkg"
android:layout_weight="1"/>
eclipse throws an error, although the project builds and runs and looks fine:
java.lang.UnsupportedOperationException
Exception details are logged in Window > Show View > Error Log
and the Error log simply says:
java.lang.UnsupportedOperationException
at android.graphics.Path_Delegate.native_addRoundRect(Path_Delegate.java:332)
at android.graphics.Path.native_addRoundRect(Path.java)
at android.graphics.Path.addRoundRect(Path.java:491)
at android.graphics.drawable.GradientDrawable.draw(GradientDrawable.java:330)
The worst part is that I can't use Graphical layout in eclipse when this happens. I have to edit by hand and can't see the layout unless and until I fire up the app in the emulator.
Anyone else have this problem with shapes, xml and eclipse?
issue reported here :
http://code.google.com/p/android/issues/detail?id=18472
You can try updating view to android 2.1 update1
or use android:radius instead of individual radius
Related
I'm working on a project in android studio and I'm trying to change the border to my button.
My default button when I just add it to my grid look like this:
After adding new XML file (called box_solid_border.XML) in the drawable file that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="4dp"
android:color="#000000" />
</shape>
the result is that it's creating the next shape that I can see:
and that exactly what I want to add to my button.
when I come back to my XML at the main file and add to my button the next line:
as you can see in line 226 I'm adding the background that I just created for this button to the button. and near the line, there is the exact border that I want.
but in the application, the button still stays the same as the default one with no border added to him.
Like this:
Does someone know the reason that the drawable file doesn't affect the button?
If I'm doing the same thing for a textView or something else its works perfectly fine, just the button looks like not affected by the drawable extension to him.
Thank you!
You need to add this attribute to your button:
app:backgroundTint="#null"
If it has both attributes android:background and app:backgroundTint(if you are using the default theme for your application, it has a default value), the color specified by app:backgroundTint will be cover on the shape of drawable.
For border to button try to edit box_solid_border.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:color="#color/black"
android:width="5dp"/>
<corners
android:radius="8dp"/>
<solid
android:color="#color/colorAccent"/>
</shape>
In layout xml file
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/box_solid_border"
android:text="Button"
android:textColor="#fff"
android:textSize="30sp" />
Since i updated my device to android 10 im facing a weird problem with one of my background gradients.
I have a RelativeLayout with a gradient background drawable looking like this.
<RelativeLayout
android:id="#+id/layoutSpeedLegend"
android:layout_width="match_parent"
android:layout_height="18dp"
android:background="#drawable/background"/>
My background.xml is looking like this.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:centerColor="#color/yellow"
android:endColor="#color/red"
android:startColor="#color/darkgreen"
android:centerX="50%"/>
<corners android:radius="15dp" />
</shape>
</item>
In the editors preview, everything looks fine
But on my real test device is looks like this.
Also adding android:angle="90" to my background.xml doesn't work.
Does anybody have an idea why this happens?
It's a bug reported here. And may not be resolved yet.
The workaround is set angle="0" as you mentioned in question's comment.
I'm developing the menu of my app with colors, fonts, styles. The problem is that when I've made some text-color changes and I run my app in the emulator, the emulator doesn't reflect the changes that I've made.
I have some buttons with Android-resource-file xml files where I have made the style of the buttons. And then I changed the text-color of the buttons but emulator doesn't reflect the changes.
Does anybody can help me? Thanks!
I'm running the app in Android Studio 3.4.1. I've tried cleaning cache from File>Invalidate Cache/Restart
<Button
android:id="#+id/presentaciones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:layout_marginBottom="50dp"
android:background="#drawable/presentaciones"
android:text="#string/presentaciones"
android:textColor="#android:color/background_light" />
Note that text color is background_light (white)
Background file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#FF9800"></solid>
<stroke android:color="#FFFF" android:width="2dp"></stroke>
<size android:width="150dp" android:height="150dp"></size>
</shape>
I expect that the buttons have text-color white, actually the emulator is showing with text black despite the code is right
I'm making a very basic test app in Android Studio. I am creating an xml file for a button pressed event, but for some reason it is not highlighting any keywords. I have updated android studio. I am at a loss for how to solve this, as it's a new process to me.
The message the lightbulb gives me is "Unexpected text found in layout file" when I try to define these attributes for the bt_pressed XML.
Make sure your attribute is nested properly in the tag. Like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/some_color" />
</shape>
(hint: look at the > character in your provided snippet)
Incorrectly placed ">" in line 2.
I made the rectangle below for a project recently and it worked just fine. Nest it in the in between your first shape tag.
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<shape android:shape="rectangle">
<corners android:radius="3dip" />
<solid android:color="#color/colorTwo" />
</shape>
</shape>
Alternatively, don't nest anything and change your opening shape tag to this:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
I am using a custom drawable to render a border around an Android TextView.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:bottom="1dp" android:left="-2dp" android:right="-2dp" android:top="-10dp">
<shape android:shape="rectangle" >
<stroke android:width="1dp" android:color="#color/pale_grey" />
<solid android:color="#00FFFFFF" />
<padding android:left="24dp" android:right="24dp"
android:top="12dp" android:bottom="12dp" />
</shape>
</item>
</layer-list>
This works fine at runtime but is not rendered in Xamarin Studio Designer (or the designer in Visual Studio) when viewing an Activity that has a TextView with that background applied e.g.
<TextView
android:id="#+id/txtHeightSelection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:textSize="#dimen/text_size_large"
android:text="Height"
android:textStyle="bold"
android:textColor="#1f2233"
android:background="#drawable/customborder2"
local:MvxBind="Click AddEntryCommand, CommandParameter='Height'" />
Unsuprisingly this is a PITA as I have to Build and deploy the app just to check some simple styling. Is this a known issue?
This is a known issue that is being addressed in a coming release (flagged as 5.7):
Bug 22243 - Android designer on XS and VS does not render Drawable shapes
As a workaround, open the drawable file in a hex editor (included in Xamarin Studio) and remove the first three bytes if they are this sequence: EF BB BF.
From Bugzilla:
The issue comes from the fact that our Android rendering process doesn't like
the UTF-8 BOM sequence we forcefully add to XML files in some places.
A simple workaround is to open the drawable XML files in an editor that doesn't
write a BOM and re-save the file from there. You can also open it up in an
hexadecimal editor and remove the first three bytes of the file (before the
initial '<').