简体   繁体   中英

how to show a snippet type of message for a Imagebutton?

I wanted to show a message over a Imagebutton so that the user knows he has to select an image using Imagebutton.

The type of error message which can be shown using the EditText.setError("Error") method I'm looking for this type of message. Is there any way of showing it for a Imagebutton? as setError only works for Edittext.

Or the type of Marker snippet message on Google maps?

I don't want to use alert dialogs as they are big and occupy large space !

Try this:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageButton
            android:id="@+id/imgBt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/falcao_large"/>

        <TextView
            android:id="@+id/errorText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/imgBt"
            android:layout_alignBottom="@+id/imgBt"
            android:background="@drawable/popup_inline_error"
            android:text="Click me first" 
            android:visibility="gone"/>

    </RelativeLayout>

Search for popup_inline_error.9.png at Android SDK folders and copy it to your res/drawable folder.

On your onClick event you can show the error message:

TextView tv = (TextView) findViewById(R.id.errorText);
tv.setVisibility(View.VISIBLE);  

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM