UnsupportedOperationException in custom view - android

I have a custom view which throws on some devices the UnsupportedOperationException. It looks like that:
java.lang.UnsupportedOperationException
at android.view.GLES20Canvas.clipPath(GLES20Canvas.java:287)
[...]
I know there's the setLayerType method but this is only supported since API level 11. How do I fix that problem for API level 8?
Here's a similar thread but the solution doesn't work for me because I'm using API level 8.

You can define layerType in layout XML.
<com.nth.android.ui.view.CircularProgressBar
android:layout_width="96dp"
android:layout_height="96dp"
android:background="#android:color/white"
android:src="#android:color/black"
android:layerType="software" />
The project where I've used features unsupported by hardware acceleration had target SDK version set to 14 and minimum SDK version was 8. Attribute layerType="software" worked on both Honeycomb (Android 3.2) and Gingerbread (Android 2.3.3).
Also, in some cases layerType="software" has to be set for view groups (layouts) that contain view in question.

Related

setTooltipText() and android:tooltipText are not working in Nougat

I have an ImageButton, when I did some test for my app, I found that I could not show the tooltipText in my Xiaomi Note 4 with Android N device. But it shows up perfectly fine in my Samsung S8 with Android O, any idea why this can happen and how to mitigate this? The minimum reproducible code is really simple, just create a basic android project in android studio and replace the default HelloWorld Textview to
<ImageButton
android:layout_width="36dp"
android:layout_height="36dp"
android:tooltipText="Show tooltip"
android:src="#mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
I think there must be some way I can make it work because the auto generated toolbar obviously has tooltip. So there must be something I'm missing to make it work in Xiaomi device.
setTooltipText (CharSequence tooltipText) is added in
added in API level 26. To use it in devices with API level prior 26, you can use TooltipCompat#setTooltipText(View view, CharSequence tooltipText) from v7 support library.
To use it, add this in gradle
implementation "com.android.support:appcompat-v7:27.1.1"
Example:
`TooltipCompat.setTooltipText(view, "Tooltip text");`

android:tint on background drawable of a layout on sdk<21

I know there are many topics discussing tint functionality prior to sdk 21, but
they either use some kind of imageviews (which I dont) or solve it programmatically (which I dont want to).
My case:
I have a constraint layout with a 9-patch drawable as background:
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/testDrawable">
This is my drawable:
<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/ninepatchdrawable"
android:tint="#color/lightBlue"
android:tintMode="multiply" />
This works fine for updated devices, but as I said the tint isn't working for devices sdk < 21. I don't get any kind of error message either.
I already tried changing my layout to:
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/testDrawable"
android:backgroundTint="#color/lightBlue"
android:backgroundTintMode="multiply">
or using app:backgroundTint as suggestet in another question.
Thanks in advance
You can try something like this:
ImageView.getDrawable().setColorFilter(new PorterDuffColorFilter(context.getResources().getColor(**color**), PorterDuff.Mode.SRC_IN));
Don't believe it'll work with a lower API -> but its a good way to change tint on the fly
There is an obvious reason why.
If you check the docs. The first part of the first line is:
With Android 5.0 (API level 21) and above,
Because android:tint was added with material design in API 21. And because it was added in API 21, it is a tag that has no meaning on API 20 and lower.
Using the support library (appcompat library) should allow you to use it. You need to add another namespace, but that isn't the biggest job to do. You can also do it in styles.xml
And backgroundTint is something completely different as you can see in this question

Views and atributtes from android layout

Hy,
When using views and atributtes like the next ones configuring an android layout:
<ImageView
android:src="#android:drawable/ic_partial_secure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="#+id/imageView" />
The number of views and values of these atributtes depend on the api level you are working on?
If it does, how can I know I am not using an atributte or a view that will not be present on an Android device with an api which not contains this atributte?
Thanks
Yes, there are some attributes that require a min API, take a look at this:
android:actionBarStyle requires API level 11
if it does and your min API level (in your build.gradle) is too low then android will tell you.

Unknown attribute android:elevation

I'm trying to follow a tutorial that suppose to show how to add a floating button and in the tutorial it says to add the attribute android:elevation to the buttons xml like this:
<ImageButton
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/editButton"
android:layout_gravity="center|right"
android:clickable="false"
android:background="#drawable/edit_grey"
android:layout_marginRight="1dp"
android:elevation="#dimen/elevation_low"/>
but it dosen't recognize that attribute...i believe it has something to do with my project target or sdk...can somebody help me?
To use android:elevation, just as with any other Android 5.0 API, you must compile against Android 5.0 (API 21). This does not mean you have to change your target SDK level or minimum SDK level.
Note: your XML file may still give a warning that android:elevation only works on Android 5.0 or higher. This warning just serves to tell you that previous versions of Android will not have an elevation shadow on the floating action button. However, that does not cause an error - previous versions of Android will ignore XML attributes they do not understand.
The Elevation attribute is pretty new. It defines the lift of the view it is applied to. It is used for the Material Design in the newest Android Versions.
Material Design
You can use it on API Level 21, I guess your targeted Level is lower than this.
If you just want to achieve some shadowing you can use this:
Shadow Drawables for Views
Or you can use the SupportLibrary with CardViews or something like that, they support elevation from API Level 7:
[How-to] Use the v21 Support Libs on Older Versions & Target L While Remaining Backwards-Compatible
Hope this helps.

Adding View in xml layout android 2.2+

I use this code in order to adding a line between my GUI componenets
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#3f9fe0"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/titleOfSection"
android:id="#+id/sectionLine"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
but it seemst that View is supporting from android api level 14+. I am using support library so it is possible to change this code in a way that android 2.2+ support the View too?
You are wrong, Views was created since api 1 as stated in the documentation.
I just tried your code with a minimum of 1 and maximum of 8 and it still works maybe you are referring to a different View, because if View does not exist since api 1 then buttons, TextView, etc wont exist as well because they inherits from View.

Categories

Resources