Android: Long-Click text on button

Issue

In my android-app I’m trying to create a button with two lines of text. One will display what the button is doing when (short) clicked, the other one should show the effect when long-clicked and that the button can be long-clicked. Just like on the the standerd keyboard of the android system (see picture).

What i’ve tried:

Bitmap canvasBitmap = Bitmap.createBitmap(64, 24, Bitmap.Config.ARGB_8888);
Canvas imageCanvas = new Canvas(canvasBitmap);
Paint imagePaint = new Paint();
imagePaint.setTextAlign(Align.CENTER);
imagePaint.setTextSize(14f);
imageCanvas.drawText(String, pxwidth/2, pxheight, imagePaint);
image = new BitmapDrawable(canvasBitmap);
((TextView) findViewById(R.id.button)).setCompoundDrawables(null,image,null,null);

But it isn’t suported at my currend API version (API 9 / GINGERBREAD / Android 2.3)
Can you please help me out?

Solution

If you need to target 9, then you can’t use that function, and you’ll need to use another technique. One way I can think of is to use an ImageButton instead of a button, prerender the image of the entire button, and apply it to the new ImageButton in xml.

Answered By – Gabe Sechan

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.