Android 在自定义样式中将自定义按钮用作父级

Android 在自定义样式中将自定义按钮用作父级,android,android-styles,Android,Android Styles,在我的项目中,我为我的按钮使用特殊字体。因此,我添加了这个库,以便可以用xml设置字体 <com.neopixl.pixlui.components.button.Button android:id="@+id/btn_login" style="@style/custom_button_style" android:layout_width="match_parent" android:lay

在我的项目中,我为我的按钮使用特殊字体。因此,我添加了这个库,以便可以用xml设置字体

<com.neopixl.pixlui.components.button.Button
            android:id="@+id/btn_login"
            style="@style/custom_button_style"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/login"
            pixlui:typeface="AvenirNextCondensed-Regular.ttf" />


        <com.neopixl.pixlui.components.button.Button
            android:id="@+id/btn_register"
            style="@style/custom_button_style"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/make_new_profile"
            pixlui:typeface="AvenirNextCondensed-Regular.ttf" />


        <com.neopixl.pixlui.components.button.Button
            android:id="@+id/btn_broker_register"
            style="@style/custom_button_style"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/make_new_profile_broker"
            pixlui:typeface="AvenirNextCondensed-Regular.ttf" />

这些是我的按钮,因为它们都有相同的字体,我想在“自定义按钮样式”中包含这些字体

这是我的定制风格:

<style name="custom_button_style" parent="@android:style/Widget.Button">
    <item name="android:textSize">@dimen/hello_medium_fontsize</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:background">@drawable/custom_btn_background</item>
    <item name="android:layout_marginBottom">@dimen/login_button_margin</item>
</style>

@dimen/您好(中号)
@android:彩色/白色
@可绘制/定制背景
@尺寸/登录按钮\u边距
我如何包括

pixlui:字体


这种款式

我们不清楚是否看不到完整的xml布局文件,但经常发生的事情是,用户忘记将xmlns属性添加到父级。您的父布局应该如下所示。它是这个图书馆的一部分,重要的是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pixlui="http://schemas.android.com/apk/com.neopixl.pixlui" <----thats the important attribute
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

AvenirNextCondensed Regular.ttf是否有效?否,我收到一个错误“未找到与给定名称匹配的资源:attr”pixlui:typeface“。是否必须更改父级?是否已将此属性设置为父级布局?:xmlns:pixlui=”“。通常,您可以使用pixluiattributes@Opiatefuchs我已经将该属性设置为父布局,在布局中使用该属性没有问题。但我想在我的样式中包含该属性,以避免在每个按钮中都包含该属性。这一个幸运吗?
  <?xml version="1.0" encoding="utf-8" ?>
   <resources xmlns:pixlui="http://schemas.android.com/apk/com.neopixl.pixlui">
     <style "custom_button_style" parent="@android:style/Widget.Button">
    <item name="android:textSize">@dimen/hello_medium_fontsize</item>
    <item name="android:textColor">@android:color/white</item>
    <item name="android:background">@drawable/custom_btn_background</item>
    <item name="android:layout_marginBottom">@dimen/login_button_margin</item>
    <item name="pixlui:typeface">AvenirNextCondensed-Regular.ttf</item> 
 </style>