这是我用来生成通知的示例代码。到目前为止,我能够收到英文通知。但现在我想在通知栏上收到另一种语言通知(“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 目录中(复制并粘贴)。
对于示例,使用两个编辑文本字段和一个按钮创建 main.xml 文件。
<?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());
}
}
您可以对标题和通知栏执行相同的操作!
关于android - 我想将 android 通知标题和内容更改为另一种语言(更改为 "Sinhala")我该怎么做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19063164/