2011-12-28 9 views
0

がところで私はちょうどので、私の知る限り、私のmain.xmlがEclipseの藍のカスタムボタンを使用すると、ボタン消える

<Button 
android:id="@+id/LOGIN" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="@string/LOGIN" 
android:textSize="25dp" 
android:background="@drawable/custombutton"/> 

custombutton.xml

を読み込み言うことができるようにすべての私のコードが正しいだアイブ私と一緒にクマ学んでいます
<item 
android:state_pressed="true" 
android:drawable="@drawable/musicnotes1"/> 
<item 
android:state_focused="true" 
android:drawable="@drawable/musicnotes2"/> 

はcustombutton.java

import android.app.Activity; 
import android.os.Bundle; 

public class custombutton extends Activity{ 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.drawable.custombutton); 
    } 
} 

を作成し、私はアンドロイドが同様にエラーを訂正しないマニフェスト持っていますなぜ私のボタンが消えてしまったのか?

答えて

1

あなたはそれが例えばR.layout.main

あるべきときR.drawable.custombuttonであるためにあなたのコンテンツビューを設定している:

setContentView(R.drawable.custombutton); 

は次のようになります。また

setContentView(R.layout.main); 

、あなたが投稿あなたのmain.xmlソースを確認してくださいレイアウトの内部にある。例えば

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <Button 
     android:id="@+id/LOGIN" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/LOGIN" 
     android:textSize="25dp" 
     android:background="@drawable/custombutton"/> 

</LinearLayout> 

そして、あなたの背景描画可能なセレクタが、このようなセレクタでラップする必要があります:

<?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/musicnotes1" 
    /> 
    <item 
     android:state_focused="true" 
     android:drawable="@drawable/musicnotes2" 
    /> 
    <item 
     android:drawable="@drawable/default" 
    /> 
</selector> 

おそらくあなたは、デフォルトのイメージを持つことを忘れていますか?

関連する問題