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");`
Related
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.
I have a checkbox that on Lollipop devices looks like material design guildelines suggest. However, when I open this check box on old android devices, it looks like a default checkbox there.
What is the right way of making sure ALL standard components look on old (14+) android versions same as in Lollipop?
Use support libraries and android.support.v7.widget.AppCompatCheckBox
<android.support.v7.widget.AppCompatCheckBox
android:id="#+id/checkbox_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/white"
/>
My layout code below, using android:layout_alignStart, was working flawlessly in Eclipse. However, recently I switched to the official Android Studio. When I use the alignStart property there, Android Studio underlines it with a wavy red line and says "To support older versions than API 17(project specifies 9) you should also add android:layout_alignLeft="#+id/textview1".
However, I tried replacing it as recommended by Android Studio, and I do not get the output alignStart was supposed to give! I am trying to place dataView2 to the right of textView2, but it currently lies on top of textView2...
<TextView
android:id="#+id/dataView2"
android:layout_toRightOf="#+id/textView2"
android:layout_alignStart="#+id/dataView1"
android:layout_alignBelow="#+id/dataView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/planet_mass_label" />
Currently your minSdk is 9, so you're getting that red line which says "To support older versions than API 17(project specifies 9) you should also add android:layout_alignLeft="#+id/textview1".
Refer this link: http://android-developers.blogspot.in/2013/03/native-rtl-support-in-android-42.html
If you want your minSdk to be 9 or less than 17, than you should use both, android:layout_alignLeft="#+id/dataView1"
android:layout_alignStart="#+id/dataView1"
accordingly.
Since your original code uses layout_alignStart="#+id/dataView1", the line you should add for pre-API 17 compatibility is
android:layout_alignLeft="#+id/dataView1"
not
android:layout_alignLeft="#+id/textView1"
The final code should be
<TextView
android:id="#+id/dataView2"
android:layout_toRightOf="#+id/textView2"
android:layout_alignStart="#+id/dataView1"
android:layout_alignLeft="#+id/dataView1"
android:layout_alignBelow="#+id/dataView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/planet_mass_label" />
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.
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.