답변:
2020 업데이트 :
res 폴더 안에 font 라는 폴더를 만들고 글꼴을 복사하십시오.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/abc_font" />
프로그래밍 방식으로 사용하는 경우 :
textView.setTypeface(ResourcesCompat.getFont(context, R.font.abc_font))
파일> 새로 만들기> 폴더> 자산 폴더를 선택하십시오.
완료를 클릭하십시오
자산을 마우스 오른쪽 버튼으로 클릭하고 글꼴 이라는 폴더를 만듭니다.
자산 > 글꼴 에 글꼴 파일을 넣습니다.
아래 코드를 사용하여 textView의 글꼴을 변경하십시오.
TextView textView = (TextView) findViewById(R.id.textView);
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/yourfont.ttf");
textView.setTypeface(typeface);
필드에서 사용자 정의 글꼴 모음을 설정하는 방법은 여러 가지가 있으며 아래에서 이와 같이 사용하고 있습니다.
글꼴을 리소스로 추가하려면 Android Studio에서 다음 단계를 수행하십시오.
1) res 폴더를 마우스 오른쪽 단추로 클릭하고 새로 작성> Android 자원 디렉토리로 이동하십시오. New Resource Directory 창이 나타납니다.
2) 리소스 유형 목록에서 글꼴을 선택한 다음 확인을 클릭하십시오.
참고 : 자원 디렉토리의 이름은 글꼴이어야합니다.
xml 파일에서 원하는보기로 글꼴을 추가하십시오.
참고 : 그러나 다음 사항이 필요했습니다.
3.0 카나리아 이상인 Android Studio.
귀하의 활동은 AppCompatActivity를 확장합니다.
Gradle 파일을 다음과 같이 업데이트하십시오.
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildtoolsVersion26 이상, 최소 targetSdkVersion요구 26
classpath 'com.android.tools.build:gradle:3.0.0-beta4'
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
.ttf 파일을 다운로드하는 대신 Google 글꼴을 사용할 수 있다고 생각합니다. 구현하기가 매우 쉽습니다. 이 단계를 따라야합니다.
1 단계) 프로젝트의 layout.xml을 열고 속성에서 글꼴보기 텍스트 글꼴을 선택하십시오 (참조 스크린 샷이 첨부되어 있습니다)

2 단계) 글꼴 모음에서 글꼴이없는 경우 추가 글꼴 .. 옵션을 선택하십시오. 그러면 새 창이 열리면 필요한 글꼴을 입력하고 해당 목록에서 원하는 글꼴을 선택할 수 있습니다. 예를 들어 아래 이미지와 같이 일반, 굵게, 기울임 꼴 등.

단계 3) 그런 다음 선택한 글꼴 xml 파일이있는 / res 폴더에 글꼴 폴더가 자동으로 생성됩니다.
그런 다음이 글꼴 패밀리를 xml에서 직접 사용할 수 있습니다.
android:fontFamily="@font/josefin_sans_bold"
또는 문법적으로 당신은 이것을 사용하여 이것을 달성 할 수 있습니다
Typeface typeface = ResourcesCompat.getFont(this, R.font.app_font);
fontText.setTypeface(typeface);
안녕하세요 .Android에서 EditTexts 및 TextViews에 글꼴을 한 번에 적용하고 전체 프로젝트에 적용하는 더 좋은 방법이 있습니다.
우선 fonts 폴더를 만들어야합니다. 다음은 단계입니다.
1 : (프로젝트 폴더)로 이동 한 다음 app> src> main
2 : 기본 폴더에 'assets / fonts'라는 폴더를 만듭니다.
3 : 글꼴을 글꼴 폴더에 넣습니다. 여기에 'MavenPro-Regular.ttf'가 있습니다.
다음은 EditText에 사용자 정의 글꼴을 적용하는 단계이며이 방법을 사용하면 모든 입력에 글꼴을 적용 할 수 있습니다.
1 : MyEditText 클래스 만들기 (원하는 이름 ...)
2 : EditText를 확장
3 : 서체를 적용하십시오
다음은 코드 예제입니다.
public class MyEditText extends EditText {
public MyEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public MyEditText(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MyEditText(Context context) {
super(context);
init();
}
private void init() {
if (!isInEditMode()) {
Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "fonts/MavenPro-Regular.ttf");
setTypeface(tf);
}
}
}
그리고 여기에 그것을 사용하는 코드가 있습니다.
MyEditText editText = (MyEditText) findViewById(R.id.editText);
editText.setText("Hello");
또는 xml 파일에서
<MyEditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#fff"
android:textSize="16dp"
android:id="@+id/editText"
/>
Support Library 26.0 (및 Android O)을 사용하면 다음을 통해 리소스에서 쉽게 글꼴을로드 할 수 있습니다.

Typeface typeface = ResourcesCompat.getFont(Context context, int fontResourceId)
자세한 내용은 여기를 참조하십시오.
Android-O 및 Android Studio 2.4에 대한 답변을 추가하고 싶습니다.
res 폴더 아래에 font 라는 폴더를 만듭니다 . 프로젝트 예 Google 글꼴에 추가하려는 다양한 글꼴을 다운로드하십시오.
xml 사용자 글꼴 패밀리 내부
예 :
<TextView
android:fontFamily="@font/indie_flower"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="@string/sample_text" />
3. 프로그래밍 방식으로 사용하려면 다음 코드를 사용하십시오.
Typeface typeface = getResources().getFont(R.font.indie_flower);
textView.setTypeface(typeface);
자세한 내용은 내 블로그 게시물에 대한 링크를 따르십시오 .Android Studio 2.4가 설치된 Android의 글꼴 스타일
Android O에서 제공되는 새로운 기능에 따라 XML의 글꼴 리소스를 새로운 기능으로 사용할 수 있습니다.
글꼴을 리소스로 추가하려면 Android Studio에서 다음 단계를 수행하십시오.
1) res 폴더를 마우스 오른쪽 단추로 클릭하고 새로 작성> Android 자원 디렉토리로 이동하십시오 . New Resource Directory 창이 나타납니다.
2) 리소스 유형 목록에서 font 를 선택한 다음 확인을 클릭하십시오.
참고 : 자원 디렉토리의 이름은 글꼴이어야합니다.
3) 글꼴 파일을 글꼴 폴더에 추가하십시오.
새로운 리소스 유형 인 font를 사용하여 글꼴 리소스에 액세스 할 수 있습니다. 예를 들어, 글꼴 리소스에 액세스하려면 @ font / myfont 또는 R.font.myfont를 사용하십시오.
예. Typeface typeface = getResources().getFont(R.font.myfont);
textView.setTypeface(typeface);
쉽고 간단한 EasyFonts 타사 라이브러리를 사용하여 다양한 사용자 정의 글꼴을에 설정할 수 있습니다 TextView. 이 라이브러리를 사용하면 글꼴을 다운로드하여 자산 / 글꼴 폴더에 추가하는 것에 대해 걱정할 필요가 없습니다. 서체 개체 생성에 대해서도. 자산 폴더를 만들지 않아도됩니다.
간단히:
TextView myTextView = (TextView)findViewById(R.id.myTextView);
myTextView.setTypeface(EasyFonts.robotoThin(this));
이 라이브러리에서 제공하는 많은 글꼴이 있습니다.
첫 번째 글꼴 폴더에 font.ttf 파일을 추가하십시오. 그런 다음 onCreate 메소드 에이 줄을 추가하십시오.
Typeface typeface = ResourcesCompat.getFont(getApplicationContext(), R.font.myfont);
mytextView.setTypeface(typeface);
그리고 여기 내 XML이 있습니다
<TextView
android:id="@+id/idtext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:gravity="center"
android:text="My Text"
android:textColor="#000"
android:textSize="10sp"
/>
textView에 글꼴을 할당하려면
TextView textView = (TextView) findViewById(R.id.your_textView);
final Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/your_font_name");
your_font_name에 글꼴 확장자가 포함되어 있습니다.
Android 8.0 (API 26)에는 글꼴과 관련된 새로운 기능이 도입되었습니다.
1) 글꼴을 리소스로 사용할 수 있습니다.
2) 다운로드 가능한 글꼴.
Android 애플리케이션에서 외부 글꼴을 사용하려면 APK에 글꼴 파일을 포함하거나 다운로드 가능한 글꼴을 구성 할 수 있습니다.
APK에 글꼴 파일 포함 : 글꼴 파일을 다운로드하고 res / font filer에 저장하고 글꼴 모음을 정의하고 스타일에 글꼴 모음을 사용할 수 있습니다.
사용자 지정 글꼴을 리소스로 사용하는 방법에 대한 자세한 내용은 http://www.zoftino.com/android-using-custom-fonts를 참조하십시오 .
다운로드 가능한 글꼴 구성 : 글꼴 제공자 세부 사항을 제공하여 글꼴을 정의하고 글꼴 제공자 인증서를 추가하고 스타일에서 글꼴을 사용하십시오.
다운로드 가능한 글꼴에 대한 자세한 내용은 http://www.zoftino.com/downloading-fonts-android를 참조하십시오 .
먼저 assets폴더를 만든 다음 폴더를 만듭니다 fonts.
그런 다음 벨로우즈 font에서 설정 assets하거나 directory좋아할 수 있습니다 .
public class FontSampler extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.custom);
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/HandmadeTypewriter.ttf");
tv.setTypeface(face);
File font = new File(Environment.getExternalStorageDirectory(), "MgOpenCosmeticaBold.ttf");
if (font.exists()) {
tv = (TextView) findViewById(R.id.file);
face = Typeface.createFromFile(font);
tv.setTypeface(face);
} else {
findViewById(R.id.filerow).setVisibility(View.GONE);
}
}
}
app / src / main / assets의 자산 폴더에 글꼴을 추가하십시오.
class CustomLightTextView : TextView {
constructor(context: Context) : super(context){
attachFont(context)
}
constructor(context: Context, attrs: AttributeSet): super(context, attrs){
attachFont(context)
}
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
attachFont(context)
}
fun attachFont(context: Context) {
this.setTypeface(FontCache.getInstance().getLightFont(context))
}
}
FontCache 추가 : 서체를 반복해서 만들 필요가 없습니다.
class FontCache private constructor(){
val fontMap = HashMap<String,Typeface>()
companion object {
private var mInstance : FontCache?=null
fun getInstance():FontCache = mInstance?: synchronized(this){
return mInstance?:FontCache().also { mInstance=it }
}
}
fun getLightFont(context: Context):Typeface?{
if(!fontMap.containsKey("light")){
Typeface.createFromAsset(context.getAssets(),"Gotham-Book.otf");
fontMap.put("light",Typeface.createFromAsset(context.getAssets(),"Gotham-Book.otf"))
}
return fontMap.get("light")
}
}
그리고 당신은 끝났습니다!
PSAndroid O에서 직접 글꼴을 추가 할 수 있습니다.
자산 폴더에 글꼴을 넣고 fontfamily를 적용하십시오 :``당신의 글꼴
새로운 독자를위한
이 라이브러리를 사용할 수 있습니다. Gloxey Custom Font Views
gradle 의존성
dependencies{
compile 'io.gloxey.cfv:custom-font-views:1.0.2'
}
사용하는 방법?
폴더 자산 -> 글꼴을 만듭니다 . 서체를 서체 폴더 로 복사하십시오 .
app : font_name = "font_name_string" 속성을 사용 하여보기에 글꼴을 적용하십시오.
예
<!--Font Names in srings.xml-->
<string name="aadhunik">aadhunik.ttf</string>
<string name="kung_fool">kungfool.ttf</string>
<string name="skrova">skrova.otf</string>
<string name="painting_in_the_sun_light">painting_in_the_sun_light.ttf</string>
<!--Include views in layout.xml-->
<io.gloxey.cfv.CFTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Aadhunik"
android:textColor="#ff00"
android:textSize="40sp"
app:font_name="@string/aadhunik" />
<io.gloxey.cfv.CFButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Kung Fool"
android:textColor="#154748"
app:font_name="@string/kung_fool" />
<io.gloxey.cfv.CFEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Hello world"
android:textSize="30sp"
app:font_name="@string/skrova" />
<io.gloxey.cfv.CFCheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Painting In The Sun Light"
android:textSize="30sp"
app:font_name="@string/painting_in_the_sun_light" />