1
기본적으로 ttf 글꼴을 라이브러리 프로젝트로 가져 오려고합니다. 하지만 몇 가지 문제가 있습니다. assets/fonts 폴더에서 ttf를 가져올 수 없으므로 res/raw로 가져 오려고했습니다. 솔루션을 찾고 있지만 대부분의 사람들이 비 라이브러리 프로젝트로 가져오고 Typeface.createFromAsset을 사용하기 때문에 구체적인 내용이없는 것 같습니다. android 라이브러리에서 사용자 정의 글꼴을 사용하는 방법
나는 사용자 지정보기를 사용하는 XML로로드 어려움 갖는<com.demo.helpers.TextFontView
android:id="@+id/login_title_lbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mob_LogIn"
android:textColor="@color/white"
android:textSize="@dimen/font_login"
demo:fontFace="+id/opensans-regular"
/>
가 TextFontView 서브 클래스에 다음 코드를 구현하기 위해 노력했습니다,하지만 난 이전에 연결하려고 몇 가지 어려움을 겪고 있어요 XML :
public static Typeface getgetTypefaceFromRes(Context context, int resource)
{
Typeface typeFace = null;
InputStream is = null;
try {
is = context.getResources().openRawResource(resource);
}
catch(NotFoundException e) {
Log.e("Typeface", "Could not find font in resources!");
}
String outPath = context.getCacheDir() + "/tmp" + System.currentTimeMillis() + ".raw";
try
{
byte[] buffer = new byte[is.available()];
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outPath));
int l = 0;
while((l = is.read(buffer)) > 0)
bos.write(buffer, 0, l);
bos.close();
typeFace = Typeface.createFromFile(outPath);
// clean up
new File(outPath).delete();
}
catch (IOException e)
{
Log.e("Typeface", "Error reading in font!");
return null;
}
Log.d("Typeface", "Successfully loaded font.");
return typeFace;
}
시도해 봤지만 거기에 ttf가 없습니다. http://developer.android.com/tools/projects/index.html 라이브러리 프로젝트에 원시 애셋을 포함 할 수 없습니다. 이 도구는 라이브러리 프로젝트에서 애셋 파일 (assets/디렉토리에 저장 됨)의 사용을 지원하지 않습니다. 애플리케이션에서 사용하는 모든 자산 리소스는 애플리케이션 프로젝트 자체의 자산/디렉토리에 저장해야합니다. 그러나 res/디렉토리에 저장된 자원 파일이 지원됩니다. – Frank