簡體   English   中英

如何在Android中以按鈕樣式設置自己的背景

[英]How to set own background in style of button in Android

我在樣式文件中制作了自己的按鈕樣式。 看起來像這樣:

按鈕樣式

  <style name="ButtonSettings" parent="@android:style/Widget.Button">
    <item name="android:layout_width">match_parent</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
    <item name="android:background">@drawable/BaseButtonDesign</item>
 </style>

BaseButtonDesign.xml

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/BaseButtonPressed"
        android:state_pressed="true" />
  <item android:drawable="@drawable/BaseButtonPressed"
        android:state_focused="true" />
  <item android:drawable="@drawable/BaseButtonReleased" />
</selector>

但是,當我編譯此代碼時,編譯器會給我錯誤消息-找不到與給定名稱匹配的資源(在“ android:background”處,值為“ @ drawable / BaseButtonDesign”)

您的文件名正確嗎? 可繪制文件的名稱只能包含小寫字母和數字([a-z0-9_。])。

我建議您僅將小寫字母,數字和下划線用作可繪制對象的名稱

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM