我已经为应用程序使用了自定义样式,而我正在使用' TextInputLayout'小工具,但当我试图更改edittext的字体时,它没有被应用。虽然当我没有使用' TextInputLatout'小部件,字体工作正常。
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
<item name="android:editTextStyle">@style/RobotoEditTextStyle</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="MyCustomToolBarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">#000</item>
<item name="android:textColorSecondary">#FFF</item>
</style>
<style name="RobotoTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif-light</item>
</style>
<style name="RobotoEditTextStyle" parent="android:Widget.EditText">
<item name="android:fontFamily">sans-serif-light</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="Base.ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="TextLabel" parent="TextAppearance.AppCompat">
<item name="android:fontFamily">sans-serif-light</item>
</style>
</resources>
以下是代码内部活动
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<include layout="@layout/app_bar"
android:id="@+id/app_bar"
android:layout_alignParentTop="true"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<LinearLayout
android:layout_below="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>
<android.support.design.widget.TextInputLayout
android:id="@+id/error_et_login_email"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
style="@style/Widget.AppCompat.EditText"
android:id="@+id/et_login_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/error_et_login_password"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.github.itwenty.passwordedittext.PasswordEditText
android:id="@+id/et_login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
app:passwordPeek="true" />
</android.support.design.widget.TextInputLayout>
<RelativeLayout
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_login_create_account"
android:layout_alignParentLeft="true"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create Account?"
/>
<TextView
android:id="@+id/tv_login_forgot_password"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot Password?"
/>
</RelativeLayout>
<Button
android:id="@+id/btn_login_login"
android:layout_alignParentBottom="true"
android:elevation="20dp"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LOGIN"
android:textColor="#FFF"
android:background="#000"
/>
</LinearLayout>
</LinearLayout>
答案 0 :(得分:0)
也许您可以在您的课程中以编程方式执行此操作,包括您在资源文件夹中的字体以及类似的内容:
Typeface tf = Typeface.createFromAsset(getAssets(), "your_font.ttf");
TextInputLayout yourtextil= (TextInputLayout) findViewById(R.id.yourTextInputLayoutId);
yourtextil.getEditText().setTypeface(tf);