2012-06-28 5 views

答えて

25

使用StateListDrawableのようなJavaからボタンの描画可能に設定することができます:あなたが描画可能リソースを設定する制御するため

StateListDrawable states = new StateListDrawable(); 
states.addState(new int[] {android.R.attr.state_pressed}, 
    getResources().getDrawable(R.drawable.pressed)); 
states.addState(new int[] {android.R.attr.state_focused}, 
    getResources().getDrawable(R.drawable.focused)); 
states.addState(new int[] { }, 
    getResources().getDrawable(R.drawable.normal)); 

imageView.setImageDrawable(states); //YOUR IMAGE HERE 
//AND FOR BUTTON 
button.setBackgroundDrawable(states);//FOR BUTTON 
+0

imageView?私は私のレイアウト内に1つをセットアップする必要がありますか? – TalMihr

+0

必要に応じて動的に作成するか、またはXmlレイアウトにImageviewを追加する –

+0

どうやって動的に行うのですか? – TalMihr

3

としてあなたはコードでセレクタをseetingため

btnSettings.setBackgroundResource(R.drawable.ic_launcher); 
関連する問題