어떻게 든 위젯 EditText
과 자산에서로드 Typeface
글꼴 정의를 사용할 수 있습니까?사용 서체
사용 서체
답변
당신이 자산/fonts 디렉토리에 상주 할 필요를 사용하려면, 당신은과 같이 액세스 글꼴 : 지금이 시도
Typeface myFont = Typeface.createFromAsset(getAssets(), "fonts/myfont.ttf");
edittext.setTypeface(myFont);
다른 대답에 요청 -하지가 위젯 작동? – hsz
네, 저에게 맞습니다. –
당신이 사용할 수있는이 당신이 파일의 구조가 가정
editText.setTypeface(Typeface.SERIF);
질문을 올바르게 읽으십시오. 그는이 –
서체 글꼴을 제공 자산의 사용자 지정 글꼴을하지 않습니다 필요 ?? –
예. 하지만 edittext –
editText.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/myfont.ttf"));
: 그에 대한 코드 아래를 참조하십시오
/assets/fonts/myfont.ttf을, 그것을 당신의 문제를 해결할 것입니다.
// text view label
TextView mTextView1 = (TextView) findViewById(R.id.TextView1);
// Loading Font Face
Typeface tf = Typeface.createFromAsset(getAssets(), "DroidSansFallback.ttf");
// Applying font
mTextView1.setTypeface(tf);
자세한 내용은 아래 링크를 참조하십시오.
용 사용자 정의 글꼴이 필요합니다. 위젯에서이 기능을 사용할 수 있습니까? @Andro 셀바으로 –
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/Comic.ttf");
youredittext.setTypeface(tf);
. 그것은 나를 위해 일했습니다. 행운을 빌어 요
위젯과 함께 사용 해본 적이 있습니까? 나는'AppWidgetProvider'을 말합니다. – hsz
아니요. 그렇다면 그것은 당신에게 효과가 없습니까? –
다른 betther 형식은 이것을 구현하고 모든 textviews에 글꼴을 추가하는 것을 피하기 위해 TextView (또는 EditText 또는 ...)를 확장하고 setTypeface 메서드에 글꼴을 적용합니다. 이 방법으로 굵게, 기울임 꼴 및 다른 스타일을 제어 할 수 있습니다. 여기
는 텍스트 뷰를 확장하고 Roboto로 폰트를 적용한 클래스에 대한 코드이다. 또한 HTML 4.0에서 Spannable을 설정하면 Android 4.0의 HTML 코드와 관련된 몇 가지 버그를 제어합니다.public class TextViewRoboto extends TextView {
public static final String TAG = "TextViewRoboto";
public TextViewRoboto(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public TextViewRoboto(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TextViewRoboto(Context context) {
super(context);
}
@Override
public void setTypeface(Typeface tf, int style) {
//This is to override eclipse error messages
if (!super.isInEditMode()) {
if (style == Typeface.BOLD)
super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Bold.ttf"));
else if (style == Typeface.ITALIC)
super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Italic.ttf"));
else
super.setTypeface(Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Regular.ttf"));
}
}
//
// With this code aboid the <b> and <strong> problem on Jelly Bean
//
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
try{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}catch (ArrayIndexOutOfBoundsException e){
//Logger.w(TAG, "Problem onMeasure. Set normal text");
setText(getText().toString());
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
@Override
public void setGravity(int gravity){
try{
super.setGravity(gravity);
}catch (ArrayIndexOutOfBoundsException e){
//Logger.w(TAG, "Problem setGravity. Set normal text");
setText(getText().toString());
super.setGravity(gravity);
}
}
@Override
public void setText(CharSequence text, BufferType type) {
try{
super.setText(text, type);
}catch (ArrayIndexOutOfBoundsException e){
//Logger.w(TAG, "Problem on setText. Set normal text");
setText(text.toString());
}
}
public void setHTMLText(CharSequence text, BufferType type) {
String tmpText = text.toString();
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
tmpText = tmpText.replace("<strong>", "<b>");
tmpText = tmpText.replace("</strong>", "</b>");
tmpText = tmpText.replace("<em>", "<i>");
tmpText = tmpText.replace("</em>", "</i>");
text = tmpText;
}
try{
super.setText(Html.fromHtml(tmpText), type);
}catch (ArrayIndexOutOfBoundsException e){
//Logger.w(TAG, "Problem on setText. Set normal text");
setText(text.toString());
}
}
}
- 1. LeagueGothic 서체 사용
- 2. "uitextview"iphone의 서체 언어를 사용 하시겠습니까?
- 3. 탭 제목의 서체 변경 - ActionBarSherlock
- 4. QApplication 서체 색상
- 5. 지정 서체 오류
- 6. 웹 사이트의 서체 글꼴
- 7. 런타임시 Textview의 서체 변경
- 8. 언어 참조, 서체 계열
- 9. CheckboxPreference의 서체 설정
- 10. android italic 서체
- 11. 로그 고양이의 서체 오류
- 12. JFace FontRegistry 서체 처리
- 13. 안드로이드 ListActivity 커스텀 서체
- 14. 서체 : Helvetica Condensed?
- 15. WebView에서 텍스트의 서체 변경
- 16. 다양한 editText에 서체 설정
- 17. RecyclerView 맞춤형 서체 어댑터
- 18. Android Studio 편집 모드에서 TextView 사용자 정의 서체 사용
- 19. 캔버스에서 드로잉을 위해 사용자 정의 서체 사용 Java Android
- 20. AlertDialog의 제목 및 버튼의 서체
- 21. 텍스트 뷰 랩 텍스트 서체
- 22. Android SearchView 제안의 서체 변경
- 23. Flying Saucer 서체 - 표시되지 않음
- 24. 중국어 및 일본어 서체 예?
- 25. CSS를 통해 서체 가져 오기
- 26. Listviews 하위 Textviews 서체 오류
- 27. 대화 제목의 사용자 정의 서체
- 28. 글꼴, 서체 및 "android L"
- 29. 변경 서체 모든 글꼴 안드로이드는
- 30. UILabel - iPhone에서 프로그래밍 방식으로 글꼴 - 서체 설정
지루한 점이 있습니까? –
나는 비트 맵 폰트를 변환하여 그것을했다,하지만 고통스러운. 나는 위젯의 레이아웃에서 커스텀'EditText'를 설정하려했지만 행운은 없습니다 (간단한'CustomEditText extends EditText'에서 내용 없음). – hsz