android - 我想将 android 通知标题和内容更改为另一种语言(更改为 "Sinhala")我该怎么做?

标签 android unicode notifications

这是我用来生成通知的示例代码。到目前为止,我能够收到英文通知。但现在我想在通知栏上收到另一种语言通知(“Sinhala”)

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("My notification ")
            .setContentText("Hello World!");

    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, View.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(View.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                0,
                PendingIntent.FLAG_UPDATE_CURRENT
            );
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(0, mBuilder.build());

最佳答案

(i)将任何僧伽罗 TTF 文件添加到项目中的 Assets 目录中(复制并粘贴)。 enter image description here

对于示例,使用两个编辑文本字段和一个按钮创建 main.xml 文件。

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="1">
    <LinearLayout android:layout_width="match_parent" android:id="@+id/linearLayout1" android:orientation="vertical" android:layout_height="wrap_content">
        <EditText android:layout_height="wrap_content" android:id="@+id/editText1" android:layout_width="match_parent">
            <requestFocus></requestFocus>
        </EditText>
    </LinearLayout>
    <Button android:text="Tnkak" android:layout_height="wrap_content" android:id="@+id/button1" android:layout_width="104dp"></Button>
    <EditText android:layout_height="wrap_content" android:id="@+id/editText2" android:layout_width="match_parent"></EditText>
</LinearLayout>

android:text="Tnkak",这个英文字母与僧伽罗语ඔබන්න(Click)单词有关。

在 LanguageAppActivity 类中

包 com.languageapp; 导入 android.app.Activity; 导入 android.graphics.Typeface; 导入 android.os.Bundle; 导入 android.view.View; 导入 android.view.View.OnClickListener; 导入 android.widget.Button; 导入 android.widget.EditText;

public class LanguageAppActivity extends Activity implements OnClickListener {
 /** Called when the activity is first created. */ 
    @Override
    public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button myButton=(Button)findViewById(R.id.button1);
        Typeface type=Typeface.createFromAsset(getAssets(), "ARADANA.TTF");
        myButton.setTypeface(type);
        myButton.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
     // TODO Auto-generated method stub
     Typeface tf = Typeface.createFromAsset(getAssets(),"ARADANA.TTF");
     EditText et=(EditText)findViewById(R.id.editText2);
     et.setTypeface(tf);
     EditText editText=(EditText)findViewById(R.id.editText1);
     et.setText(editText.getText());  
    } 
}

enter image description here

您可以对标题和通知栏执行相同的操作!

关于android - 我想将 android 通知标题和内容更改为另一种语言(更改为 "Sinhala")我该怎么做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19063164/

相关文章:

android - 更改android对话框的主题

python - Python 2.7 "wide-build"usc4 是否与某些库不兼容?

python - 如何从 unicode 字节表示中检索我的 unicode

java - Android 每日通知在错误的时间多次显示

android - 为什么Studio生成的APK小于命令行APK

javascript - 获取li内子标签的html内容

android - Github 上的问题

python - 从字符中删除重音符号,同时保留其他变音符号

iOS UILocalNotification 是操作按钮崩溃并损坏应用程序数据

android - 如何使用 Ionic 2 增加 Android 应用程序图标中的徽章计数通知?