0

I am creating an app for a non-English market. Hence, I have to change the font of the notification. So I have to use Bitmap. I want the notification to be multiline. I have the following code.

        DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
        int width = displayMetrics.widthPixels;

        Bitmap bitmapTitle = Bitmap.createBitmap(width - 72, 84, Bitmap.Config.ARGB_8888);
        Canvas canvasTitle = new Canvas(bitmapTitle);
        TextPaint paintTitle = new TextPaint();
        paintTitle.setAntiAlias(true);
        paintTitle.setSubpixelText(true);
        paintTitle.setTypeface(AppApplication.hindiFont);
        paintTitle.setStyle(Paint.Style.FILL);
        paintTitle.setColor(ContextCompat.getColor(context, R.color.positive));
        paintTitle.setTextSize(70);
        paintTitle.setFakeBoldText(true);
        paintTitle.setTextAlign(Paint.Align.LEFT);
        String longText = "vuqla/kkuksa ls irk pyk fd bl enn djrk gS fd yksx dSyksjh dh la[;k os miHkksx dks de dj fn;k gSA";
        StaticLayout staticLayout = new StaticLayout(longText, paintTitle, canvasTitle.getWidth(), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); 
        canvasTitle.save();
        staticLayout.draw(canvasTitle);
        canvasTitle.restore();

I am not using canvasTitle.drawText() as this cannot wrap a long string according to the width of the notification. Hence, I followed the method shown here suggesting the use of staticlayout.

I get the following output: enter image description here

Here only the top of the next line is displayed but not the full line. How to get the full line to be displayed using the static layout? Or why is it not displayed fully?

Here is the xml:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_notification"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="2dp">

<ImageView
    android:id="@+id/rnotification_iv_logo"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_gravity="center_vertical"
    android:src="@drawable/notification_icon"/>

<ImageView
    android:id="@+id/rnotification_iv_title"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginTop="2dp"
    android:layout_gravity="center_vertical"
    android:paddingRight="5dp" />

</LinearLayout>
Community
  • 1
  • 1
suku
  • 10,507
  • 16
  • 75
  • 120
  • Is this a language not supported by Android? – Karakuri Jul 01 '16 at 13:58
  • what is `84` in your code? and why do you use `ImageView` with `Bitmap` and not a `TextView`? – pskink Jul 01 '16 at 14:03
  • @pskink Stupid mistake. 84 was the problem. I need to use ImageView because, you cannot access the textview to change its typeface from a remoteview. Hence have to use this round about method. Please write your comment in the answer – suku Jul 01 '16 at 14:14

0 Answers0