I have created a custom xml like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:color="#color/colorAccent"
android:width="2dp"/>
<corners
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp"
android:topLeftRadius="30dp"
android:topRightRadius="30dp" />
<size
android:height="400dp"
android:width="1000dp" />
This is an empty rectangle with rounded corners. It looks well in 5.0+ android versions but when I tested it on 4.1 the rectangle filled in with black color.
Have you any idea what cause this?
Just to copy my previous comment: There's a bug on older OS versions. You need to add a solid tag in your shape as well. I'm not sure if android:color/transparent will work on these older devices though...
Related
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.
I have a custom SeekBar that uses LayerList as progress drawable. On Android device with API <22 it seems to work fine, however on API 22 the progress drawable is not displayed.
Here's my LayerList code:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#android:id/background">
<shape android:shape="rectangle">
<corners android:radius="20dp"/>
<gradient android:startColor="#0e0e0f" android:endColor="#373938" android:angle="270"/>
<stroke android:width="10dp"
android:color="#2d3035" />
<size android:height="3dp" android:width="500dp"/>
</shape>
</item>
<item android:id="#android:id/progress">
<clip>
<shape android:shape="rectangle">
<corners android:radius="20dp"/>
<solid android:color="#45ab12" />
<stroke android:width="10dp"
android:color="#2d3035" />
<size android:height="3dp" android:width="500dp"/>
</shape>
</clip>
</item>
And here's my Seekbar:
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:splitTrack="false"
android:thumbOffset="5dp"
android:id="#+id/firstAudioPositionSeekBar"
android:thumb="#drawable/seekbar_thumb"
android:progressDrawable="#drawable/seekbar_progress_bg"/>
Here are screen shots of the SeekBar on API 22 and lower:
I'm having similiar issue on API 22 and found your question. Did you find a good solution for that? What I've noticed till now, with many experiments:
1. Without solid on API 22 the progressbar is drawn
2. Stroke values are drawn different on API 22 devices than on all upper APIs, what is very strange, cause it doesn't even take care of screen size.. what the hell?
3. Even when u change stroke to proper one on API 22 - it still is MUCH MUCH different on small resolutions (480/800) and all other screen sizes..
I found a solution thought, but I don't think it is the best one. I created 3 separate drawable files (layer list): one for API 22 with small resolution, one for API 22 with all other resolutions, and one for all API's above 22. I removed stroke from those with API 22 and put inside item values:
<item android:id="#android:id/background" android:top="15dp" android:bottom="15dp">
I have tested it for 10 different phones with different resolutions - it works perfectly, even for big tablets. Still, I think there must be a better solution for this.
Best regards,
Max
I'm working on an Android application in Xamarin. For button backgrounds, I've created a simple XML. The code is:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<gradient android:startColor="#ff000000"
android:centerColor="#ffffffff"
android:endColor="#00ffffff"
android:type="radial"
android:gradientRadius="100"
/>
</shape>
</item>
</selector>
When I use linear or sweep in android:type code, everything is fine. A good transparent gradient appear in my device (My device is HTC One M8). But when I use radial, a bad solid color appears, no transparency. I want to use this technique for the shadow under buttons, but if you check the screenshot below, a very bad harshy solid color appear under the buttons.
If the code uses RGB or ARGB color, it draws a buggy solid gradient!
Is it a bug in the code, in my device or in the Xamarin deploy setting?
I've experienced a strange effect dealing with shape drawables with support lib attributes. I have following code, which crashes every time during inflation.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size android:width="26dp" android:height="26dp"/>
<solid android:color="?attr/colorPrimary"/>
Note I have used ?attr/colorPrimary as color. If I use
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size android:width="26dp" android:height="26dp"/>
<solid android:color="#color/primary"/>
It is working fine without any crashes. Issue is only in devices running lower version of Android than 5.0. I am using following support lib
compile 'com.android.support:support-v4:22.2.1'
Anyone found reason why this is happening? Is this a bug in support library?
<solid android:color="?attr/colorPrimary"/> Points to a private color (was not public) in Android code, maybe it doesn't exist in some API.
While <solid android:color="#color/primary"/> will point to a color in your project, maybe you have a color name primary only in folder values-v21 so it's only crashing in versions below 5.0
I think you should try using this:
<solid android:color="#android:attr/colorPrimary"/> to make sure the attribute exists.
Hope this helps.
i am trying to create a tab as following which is a Holo Light theme but as i am using android 2.3.6 i got to create it on my own.
the problem i am facing is i am bot be able to create the blue bottom like
here is the code so far in a drawable , can any one tell me how to create the bottom border for the same ?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="63dp">
<shape android:shape="rectangle">
<solid android:color="#898989" />
</shape>
</item>
<item android:top="63dp" android:bottom="3px">
<shape android:shape="rectangle">
<solid android:color="#color/app_background" />
</shape>
</item>
<item android:left="#dimen/tab_space" android:right="#dimen/tab_space">
<shape android:shape="rectangle">
<gradient android:angle="90" android:startColor="#d9d9d9"
android:endColor="#dfdfdf"/>
<!-- this is create a border but on every side -->
<stroke android:width="3px" android:color="#38c0f4" />
</shape>
</item>
</layer-list>
so wht i dont know is to create
1) bottom stroke
2) shadow under each tab
You could just set a 9 patch image as the background image. And this image could contain a stroke.
Even if this is not totally on topic of your question, I suggest to migrate your project to ActionBarSherlock. ActionBarSherlock lets you use all the ICS Actionbar Apis with earlier API-Levels and brings the ICS Actionbar Style to all Devices with at least Android 2.2.
Using this project will make it very easy to move your app to Ice Cream Sandwich compatibility, and solve your current design problem.