2

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

    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());
4

1 回答 1

2

(i) 将任何僧伽罗语 TTF 文件添加到项目中的资产目录(复制和粘贴)。 在此处输入图像描述

对于使用两个编辑文本字段和一个按钮的示例创建 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",这个英文字母与僧伽罗语ඔබන්න(点击)字有关。

在 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());  
    } 
}

在此处输入图像描述

你可以为你的标题和通知栏做同样的事情!

于 2013-09-28T04:45:52.330 回答