使用自定义按钮作为自定义样式的父级

时间:2014-06-20 13:12:57

标签: android android-styles

在我的项目中,我为我的按钮使用特殊字体。所以我添加了PixlUI库,以便我可以在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" />

这些是我的按钮,因为它们都有相同的字体我想在'custom_button_style'中包含字体

这是我的自定义风格:

<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>

我如何包含

  

pixlui:字体

这种风格?

1 个答案:

答案 0 :(得分:-1)

目前尚不清楚我们是否看不到完整的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"
>

您不需要在style.xml中添加内容。因此,如果这不能解决您的问题,请回来。

修改

它还没有经过测试,但它的风格可能是:

  <?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>