2016-09-03 13 views
1

Notification.Builderにテキストを表示したい。 私の言語は右から左に書かれています。 それでは、どのようにNotification.Builderのテキストとタイトルの方向を変更できますか? enter image description here右から左Notificatoin.Builder

私のコード:その後、

NotificationCompat.BigTextStyle bigTextStyle = new 
    NotificationCompat.BigTextStyle(); 

bigTextStyle.setBigContentTitle(getString(R.string.smartservice)); 
bigTextStyle.bigText(getString(R.string.aboutsmartservice)); 

Uri path = 
    RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 


Bitmap icon = BitmapFactory.decodeResource(getResources(), 
    R.drawable.ic3); 

NotificationCompat.Builder mBuilder = new 
    NotificationCompat.Builder(this); 

mBuilder.setTicker(getResources().getString(R.string.smartservice)) 

.setContentTitle(getResources().getString(R.string.smartservice)) 

.setContentText(getResources().getString(R.string.aboutsmartservice)) 
.setSmallIcon(R.drawable.ic4) 
.setLargeIcon(Bitmap.createScaledBitmap(icon, 64, 64,false)) 
.setStyle(bigTextStyle) 
.setSound(path) 
.setPriority(Notification.PRIORITY_MAX); 

Intent stopreciver = new Intent(); 
stopreciver.setAction("STOP_ACTION"); 
PendingIntent pendingIntentYes2 = 
    PendingIntent.getBroadcast(this, 12345, stopreciver, 
     PendingIntent.FLAG_UPDATE_CURRENT); 

mBuilder.addAction(R.drawable.ic_remove_circle_outline_white_18dp, 
    getResources().getString(R.string.stopservice), pendingIntentYes2); 

startForeground(101, mBuilder.build()); 
+0

私は同じ問題を抱えている、あなたは解決策を見つけましたか? –

答えて

0

使用RemoteviewとのTextViewのスタイルを変更します。最初にカスタムxmlを作成し、textviewのためにあなたが望む方向を設定します。次に、下のJavaコードを使用してカスタム通知を作成し、それを表示します。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/layout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding="10dp" > 
<ImageView android:id="@+id/image" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_marginRight="10dp" /> 
<TextView android:id="@+id/title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textDirection="anyRtl" 
    android:layout_toRightOf="@id/image" 
    style="Custom Notification Title" /> 
<TextView android:id="@+id/text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@id/image" 
    android:layout_below="@id/title" 
    android:textDirection="anyRtl" 
    style="Custom Notification Text" /> 

int icon = R.drawable.ic_launcher; 
    long when = System.currentTimeMillis(); 
    Notification notification = new Notification(icon, "Custom Notification", when); 

    NotificationManager mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification); 
    contentView.setImageViewResource(R.id.image, R.drawable.ic_launcher); 
    contentView.setTextViewText(R.id.title, "Custom notification"); 
    contentView.setTextViewText(R.id.text, "This is a custom layout"); 
    notification.contentView = contentView; 

    Intent notificationIntent = new Intent(this, MainActivity.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 
    notification.contentIntent = contentIntent; 

    notification.flags |= Notification.FLAG_NO_CLEAR; //Do not clear the notification 
    notification.defaults |= Notification.DEFAULT_LIGHTS; // LED 
    notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration 
    notification.defaults |= Notification.DEFAULT_SOUND; // Sound 

    mNotificationManager.notify(1, notification);