I stole a Xiaomi phone from my friend, android version is API17, system 4.2, but it shows 4.4.4 on the phone, I am also ha ha.
Today, when I tested my APK with this low version of mobile phone, I found that it crashed directly, and I could not locate the problem. I can show you the specific location information of the error:
So I fell into a meditation, right! Meditation!
Vector drawing, however, is Google in 5.0 system, so the above 5.0 is no problem, then decided to adopt the appropriate figure, because there is no low version of the testing machine, so I hesitated a long time, not sure on the low version there is no problem, just appeared today, in fact, according to the official, It’s easy to work with older systems. Ps: HERE I will not do how to use vector graphics, mainly for the low version of the next description, but my problem is strictly not caused by the low version of the compatibility problem.
At that time, there was a crash. The first thing THAT came to my mind was that MAYBE I was careless when USING the vector image, and the way I used it was wrong, which led to the crash on the lower version. So I “dealt with it well” and changed some things:
The second:
Third: in our Activity to invoke this sentence: the static {AppCompatDelegate. SetCompatVectorFromResourcesEnabled (true); }
Fourth: If the activity is inherited from ActivityCompat, then we can use ImageView, which will automatically convert to AppCompatImageView, if not ActivityCompat, then AppCompatImageView, For consideration, I used AppCompatImageView and setImageResource as the background in the Java code. The Settings are as follows:
In fact, the content is so much, I have been so configured and used, according to the truth is no problem, but I still crash, a little square, a little panic, a little…… Well…
I took the dead kowtow method, the first step is to read the wrong newspaper, certainly can find clues, the second step is to look at Google’s official documents.
And then I found a detail, I actually found a detail of the error
“You don’t have to use StateListDrawable. It also works with InsetDrawable, LayerDrawable, LevelListDrawable and RotateDrawable containers. The only rule is that The vector needs to be in a separate file.”
I was lost in thought and almost fell asleep.
Finding this in an official Android tweet means, We want to use the Vector in the normal controls, must be attached to the StateListDrawable, InsetDrawable, LayerDrawable, LevelListDrawable, RotateDrawable, so let me try?
And use the reference resources in the layout, so it is ok, run, perfect run!
On the vector view: first of all, it can perfectly solve the compatibility problem, the effect is still very significant, of course, has been said to complete with vector graphics with animation pit this problem I haven’t tried, but if the control with vector graphics animation in the process of movement will indeed appear distortion phenomenon; In the process of using vector graph is very troublesome test patience, graph is to import one by one, and have to manually generate drawable file to solve my above problem (should be including layout background TextView and button seem to appear problems), really a little troublesome to say. In a hurry to finish writing summary, hurriedly off work, have the opportunity to say again!