Javaを使用しdrawableBottomを変更します
質問
それは、java?
を経由してボタンを描画可能に変更することは可能です例。私はこのようなボタンがあります。
<Button
style="@style/Buttons"
android:id="@+id/butFavTeam"
android:drawableBottom="@drawable/venue"/>
私は私の描画可能ディレクトリから別のと、現在のdrawableBottomの画像を変更したい。
解決
あなたがこの方法を見てきました
/*
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.
*/
public void setCompoundDrawablesWithIntrinsicBounds (Drawable left, Drawable top, Drawable right, Drawable bottom)
これを試してみてください
/*remember to first clear the callback of the drawable you are replacing to prevent memory leaks...
* Get the Drawables for the button by calling: myButton.getCompoundDrawables(), then loop through that calling myOldDrawable.setCallback(null);
* e.g:*/
for(Drawable myOldDrawable : myButton.getCompoundDrawables())
{
myOldDrawable.setCallback(null);
}
//use null where you don't want a drawable
myButton.setCompoundDrawablesWithIntrinsicBounds(null,null,null, myNewDrawable);
私はそれが役に立てば幸います。
他のヒント
だけがそれを見つけます。
Drawable myIcon = this.getResources().getDrawable(R.drawable.myVenue);
butFavTeam.setCompoundDrawablesWithIntrinsicBounds(null, null, null, myIcon);
ところで...あなたが誤ってメソッドsetCompoundDrawablesを(使用していないことを確認してください)。それはsetCompoundDrawablesWithIntrinsicBounds()と同じパラメータを取りますが、それは明らかにあまりにもいくつかの限界の詳細を期待しています。
私が遅延し、非常に最初の先行入力方式を受け入れたため、私は、このために獲物を落ちました。私は、画像が表示されない理由をあなたも把握することはできません場合にはこれを掲示しています。
所属していません StackOverflow