Custom drawable not being rendered in Xamarin Studio - android

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 '<').

Related

How to debug what part of my app is causing it to force close (backward compatibility problem)

This is my first venture into writing any kind of code, let alone an android app. I created the project with the compileSdkVersion of 28, targetSdkVersion of 28 and minSdkVersion of 23. The app will only run on Android Pie and crashes on any previous version I have tried to install it on.
Everything compiles properly and works wonderfully on the emulator and my personal phone (both on Pie). I have read a lot about using the Android Support Library, however, I have not seen any information on how to understand which parts of your code need to use things from the support library versus the framework. Android Studio may have given me warnings along the way about using things from the support library, but being new at this, I did not know what it meant or what my proper choice should be. Now that I understand, I don't know how to attack going back and finding (and then fixing) anything that needs to use the support libraries.
I imported com.android.support:appcompat-v7 and have used AppCompatActivity instead of Activity. In a nutshell, I use textViews, editTexts, spinners and a TabHost (with two tabs). I think that the ActionBar might be a problem as well, but do not know how to see if that is the problem and how to fix it.
The rest of the code is mathematical calculations with a bunch of if/then/else statements and some switch statements.
The app force closes when it is opened after being installed on any OS prior to Android Pie.
Snippet from content_main.xml (layout):
<Spinner
android:id="#+id/spnFromPool"
android:layout_width="176dp"
android:layout_height="34dp"
android:layout_gravity="start"
android:layout_weight="0.3"
android:background="#drawable/bg_spinner"
android:entries="#array/pool_type_array" />
bg_spinner.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/swimToolPrimary"/>
<corners android:radius="10dp" />
<stroke android:color="#000000" android:width="1dp" />
</shape>
</item>
<item android:gravity="center_vertical|right" android:right="8dp">
<layer-list>
<item android:width="12dp" android:height="12dp" android:gravity="center" android:bottom="10dp"
tools:targetApi="m">
<rotate
android:fromDegrees="45"
android:toDegrees="45">
<shape android:shape="rectangle">
<solid android:color="#color/swimToolSecondary" />
<stroke android:color="#color/swimToolSecondary" android:width="1dp"/>
</shape>
</rotate>
</item>
<item android:width="20dp" android:height="10dp" android:bottom="21dp" android:gravity="center"
tools:targetApi="m">
<shape android:shape="rectangle">
<solid android:color="#color/swimToolPrimary"/>
</shape>
</item>
</layer-list>
</item>
</layer-list>
You can check the problem in log of android studio by selecting "No Filters" in top-right corner in logcat and for filtering the data you can add package name of your app in search bar.

Android: Where to find Seekbar drawable "scrubber_control_normal_holo"

My primary problem is I want to increase the size of the thumb of the Seekbar, so I found this post: Changing size of seekbar thumb
From there it said i can create thumb_size.xml and add the below code inside:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<size
android:height="40dp"
android:width="40dp" />
<solid android:color="#android:color/transparent" />
</shape>
</item>
<item android:drawable="#drawable/scrubber_control_normal_holo"/>
However then the Android Studio give me error message saying that it cannot find the
scrubber_control_normal_holo
Then I find this post: Android: Where to find the RadioButton Drawable?
However in my SDK folder /platforms/android-17/data/res/drawable folder, I still cannot find this file, I can only find something like:
seek_thumb.xml
but when I try to use it, it still give me error.
At last I can find the resource images in the following folders (for different device size):
SDK folder\platforms\android-17\data\res\drawable-hdpi
SDK folder\platforms\android-17\data\res\drawable-mdpi
SDK folder\platforms\android-17\data\res\drawable-xhdpi
SDK folder\platforms\android-17\data\res\drawable-xxhdpi
SDK folder\platforms\android-17\data\res\drawable-xxxhdpi

couldn't find schema information in mono android style

I'm building a simple mono android app. I've designed a simple style to set the background of a textview:
The xml file in my Resouces/Drawable Folder:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#DD2ECCFA" />
<stroke android:width="1dp" android:color="#FFFFFFFF" />
<corners android:radius="7dp"/>/>
</shape>
I get the following message in vs 2012:
couldn't find schema information for the element 'shape'.
And a couple more messages for corners, stroke, solid...
This message causes problem when I install the app on a real device but on the emulator every thing is fine.
I'm using java jdk version 6. Thanks. Any help will do.

Making Android EditText look the same

I'm creating a simple login activity and I am trying to make the edittext look the same on all devices. In Android Studio it looks the same on all APIs but on real devices it looks very different. What can I do to achieve they all look the same?
This is how it looks in Android Studio
And this is how it look on a real device
Any help would be appreciated. I'm still learning Android development.
The background of widgets are API level dependent.
Set this xml to your EditText background attribute.
<?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="#4C000000"/>
<corners android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
This will have the same look and feel of your EditText on every API.
It totaly depends on the way you use the emulator. The emulator, since the common AVD (used in Eclipse, or that kind of IDEs) until the Android Studio, will gonna use the default skin to show the widgets and components in the development environment.
You can install the manufacturer device skins to simulate your emulator as the original one. Look at that description from the Samsung official website:
The Emulator Skin is a simple way to test your Android application on a simulated GALAXY S2. The emulation does not simulate all features of an actual device, however. The emulation allow you to see how your application’s display scales to the GALAXY S2's screen.
It'd improve your testability in that case, but is also recommended to always test in the real device to get a better result.
Probably it happens because you haven't specified Theme for your application. And according to the documentation android choses theme based on the following rules:
If an app does not explicitly request a theme in its manifest, Android
4.0 will determine the default theme based on the app’s targetSdkVersion to maintain the app’s original expectations: For
values less than 11, #android:style/Theme; between 11 and 13
#android:style/Theme.Holo; and for 14 and higher
#android:style/Theme.DeviceDefault.
You can find more details in the following thread.
In your drawable folder create edittext_style.xml,
<?xml version="1.0" encoding="utf-8"?>
<item><layer-list>
<item><shape>
<gradient android:angle="90" android:endColor="#ffffff" android:startColor="#ffffff" android:type="linear" />
<stroke android:width="1dp" android:color="#CECFCE" />
<corners android:radius="0dp" />
<padding android:bottom="3dp" android:left="3dp" android:right="8dp" android:top="3dp" />
</shape></item>
</layer-list></item>
Define below code in style.xml,
<!-- Edittext Style -->
<style name="edittext_style">
<item name="android:background">#drawable/edittext_style</item>
<item name="android:layout_marginLeft">10dp</item>
<item name="android:layout_marginRight">10dp</item>
<item name="android:layout_marginBottom">10dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:paddingBottom">5dp</item>
<item name="android:popupBackground">#DFFFFFFF</item>
</style>
And there you go, Just use color code as per your requirement,
<EditText
android:id="#+id/email"
style="#style/edittext_style"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />

drawable shape causing eclipse problems

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

Categories

Resources