2013-04-11 75 views
1

區域字符我有方法:顯示在android系統

public boolean dispatchKeyEvent(KeyEvent event) 
{ 
    Toast.makeText(getApplicationContext(),String.valueOf(event.getCharacters()), Toast.LENGTH_SHORT).show(); 
    ShowKeyboardSystem(false); 
    Find(event.getCharacters()); 
    return true; 
} 

不幸的是敬酒不顯示區域字符。爲什麼?

+0

*區域字符*?你什麼意思?什麼是Find()? – m0skit0 2013-04-11 18:13:48

+0

f.eóęąśćå和其他 – 2013-04-11 18:17:41

+0

找到一種搜索字符串的方法,參數 – 2013-04-11 18:18:39

回答

0

您可以顯示自定義烤麪包的字體設置爲烤麪包中的文字。我已經下載了kn.ttf(kannada的字體,它是我居住地的本地語言),並將其放在assests文件夾中,如下圖所示。

activity_main.xml中吐司

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/toast_layout_root" 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="8dp" 
      android:background="#DAAA" 
      > 
<TextView android:id="@+id/text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#FFF" 
      /> 
</LinearLayout> 

<?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" 
    > 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" /> 

</LinearLayout> 

定製alyout代碼:

public class MainActivity extends Activity { 

private TextView myTextView; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Button b= (Button) findViewById(R.id.button1); 
    b.setOnClickListener(new OnClickListener() 
    { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      LayoutInflater inflater = getLayoutInflater(); 
      View layout = inflater.inflate(R.layout.custom, 
              (ViewGroup) findViewById(R.id.toast_layout_root)); 

      TextView text = (TextView) layout.findViewById(R.id.text); 
      text.setTextColor(Color.RED); 
      text.setText("This is a custom toast"); 
      Typeface typeFace = Typeface.createFromAsset(getAssets(),"fonts/kn.ttf"); 
      text.setTypeface(typeFace); 
      Toast toast = new Toast(getApplicationContext()); 
      toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); 
      toast.setDuration(Toast.LENGTH_LONG); 
      toast.setView(layout); 
      toast.show(); 
     } 

    }); 

} 
} 

enter image description here

+0

這是否適用於Android 4.0(ICS)?我無法在我的應用程序中顯示卡納達人物。請看看這個問題http://stackoverflow.com/questions/16455923/kannada-font-on-android-ics – 2013-05-09 21:58:04