如何自定义EditText字体并保持与原始字体相同?

时间:2017-08-24 10:58:08

标签: android android-edittext

我创建此EditText以使用自定义字体

如果是TextView

,这个方法没问题

如果是EditText,文本将显示在错误的位置,我无法编辑文本,单击edittext,键盘将不会显示在屏幕上

如何解决这些问题?

public class GothamBookEditText extends android.support.v7.widget.AppCompatEditText {

    String font="Gotham-Book.ttf";
    public GothamBookEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setTypeface(Typeface.createFromAsset(context.getAssets(), font));
    }

    public GothamBookEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.setTypeface(Typeface.createFromAsset(context.getAssets(), font));
    }

    public GothamBookEditText(Context context) {
        super(context);
        this.setTypeface(Typeface.createFromAsset(context.getAssets(), font));
    }
}

enter image description here

这是styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>
<style name="AppTheme2" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
</style>

<style name="PreferencesTheme" parent="Theme.AppCompat">
    <item name="android:background">@color/bg</item>
    <item name="android:textColor">@color/colorGreyWord</item>
    <item name="android:textColorSecondary">@color/colorGreyWord</item>
    <item name="colorPrimary">@color/bg</item>
    <item name="colorPrimaryDark">@color/colorGreyWord</item>
    <item name="colorAccent">@color/colorGreyWord</item>
</style>

</resources>

0 个答案:

没有答案