2011-06-27 4 views
0

私のAndroidアプリケーションのルックアンドフィールをカスタマイズする必要があります。ボタンビューのデフォルトの外観の代わりに表示するために作成したPNGファイルが必要です。これをどうすればいいのですか?ボタンオブジェクトを画像に設定する方法

<?xml version="1.0" encoding="utf-8"?> 

<item android:state_pressed="true" android:drawable="@drawable/button_active" /> 
<item android:state_focused="true" android:drawable="@drawable/button_enabled" /> 

<item android:state_enabled="true" android:drawable="@drawable/button_enabled" /> 
<item android:state_enabled="false" android:drawable="@drawable/button_enabled"/> 

それはあなたがすべてのボタンの状態や変更のためのあなたのDrawableを定義したことができます:ここで

答えて

1
you can set the backgroung of Button as follows. 



<Button android:id="@+id/button01" 
         android:layout_height="wrap_content" 
         android:background="@drawable/savebuttonselect" 
         android:layout_width="wrap_content"/> 

、ここsavebuttonselectは、状態の変化にボタン画像を変更するために使用されるXMLファイルである

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

は私がカスタムボタンを必要なときに使用している小さなコードスニペットですそれらは自動的に。このコードを内部に持つXMLファイルを作成し、ボタンの背景描画可能ファイルとして配置するだけです。お役に立てれば。

関連する問題