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
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 am currently using a list selector for my listview and created it using layer-list. This is my xml code:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/menu_arrow"
android:width="18dp"
android:height="36dp"
android:top="5dp"/>
<item android:top="0dp" android:left="5dp" android:bottom="0dp" android:right="0dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/transparent"/>
</shape>
</item>
When i build the app, it appears fine on api 23 and above.
But for api 22 and below, it looks like this:
I came across this post Shape drawable in layer-list rendered incorrectly for APIs below 23 and understood that the attributes width and height work only for api 23 and above. So i added the width and height inside the size tag like this :
<item android:drawable="#drawable/menu_arrow"
android:top="5dp">
<size android:height="36dp" android:width="18dp"/>
</item>
But the image still appears stretched. What attribute is needed for api 22 and below to make the drawable look uniform for all the versions?
I managed to solve it in the following way :
<item android:drawable ="#drawable/menu_arrow"
android:right="285dp"
android:top="5dp"
android:bottom="10dp"/>
I guess for api < 23 we need to resize the drawable using top,right,bottom values and for api > 23 we can use width and height.
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...
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.
Is there a best practices size (in dip?) that buttons should be in order to be easily touchable?
See https://support.google.com/accessibility/android/answer/7101858?hl=en which says that a touch target should — at minimum — be 48x48dp
Outdated (see comments below): Android Design Guidelines specifically call out 48dp as the recommended minimum size for any touchable object. See "48dp Rhythm": http://developer.android.com/design/style/metrics-grids.html
You may find this helpful: http://www.lukew.com/ff/entry.asp?1085. About 8mm (50 dips) should be OK.
Just take a look at the Android Design Guidelines for Buttons:
Source: https://material.io/guidelines/components/buttons.html#buttons-style
<shape android:shape="rectangle">
<corners android:radius="1000dp" />
<solid android:color="#color/light_blue" />
<stroke android:width="2dip" android:color="#215368" />
<padding android:bottom="4dp" android:left="4dp" android:right="4dp"
android:top="4dp" />
</shape>
this for round button, make sure the width and height is same.