【发布时间】:2013-04-19 15:24:53
【问题描述】:
我有一个基于印地语内容的 android 应用程序,并使用了来自 Android API 16 SDK 的 devangiri 字体并重命名为hindi.ttf。文本在 API 级别 16 和 17 上可以正常呈现,但在 Android API 级别 15 及更低级别时会被撕裂。
有什么原因我可以在不删除对较低 API 级别的支持的情况下解决这个问题。我设置 textview 的代码是:
import android.app.Activity;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.GestureDetector;
import android.widget.TextView;
public class Prayer extends Activity {
// TextSwitcher vs;
GestureDetector gestureDetector;
static Tips tip = null;
static StringBuilder quesString = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prayer);
TextView tv1 = (TextView) findViewById(R.id.textView1);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/hindi.ttf");
tv1.setTypeface(tf);
tv1.setText("श्री");
tv1.setPaintFlags(tv1.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
}
布局 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C5C6E1"
tools:context=".Prayer" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TextView>
</RelativeLayout>
当前:
预期:
【问题讨论】:
-
使用活动上下文而不是应用程序上下文stackoverflow.com/questions/7298731/…。您可以将颜色设置为 tv.setTextColor(android.R.color.black);你可以发布一个快照。它应该可以正常工作
-
至少它用 getAppContext 显示了一些东西,但用 CurrentActivity.this,屏幕上没有出现任何文字。有没有人尝试在 android 4.0.2 (API-15) 中显示印地语文本
-
您是否通过 setContentView(tv1) 设置了 textview?我有 4.0.2 并且我使用活动上下文工作正常
-
是的,就在那里。问题是文本未正确呈现。虽然它应该如 screen1 所示,但它会如 screen2 所示。看看像 shri 这样在 screen2 中印地语拼写错误的单词。在问题中附上了屏幕截图。这是字体文件的问题吗?
-
从运行在 android jellybean 上的应用程序捕获各种分辨率的屏幕图像,然后在用户使用低于 API 16 的任何内容时显示它是否有意义