0
私のアプリはAPI 23以上でうまく動作していますが、API 21で実行するとバグがあるようです。このコードに絞っています:それは常に(場合でも、それはいけない)がfalseを返すので、私はそれらのいずれかの方法は、APIで21APIのリソースの比較21 x API 23
任意のアイデアは動作しません推測するAPI 21で
if (myButton.getBackground().getConstantState() == ResourcesCompat.getDrawable(getResources(), R.drawable.myDrawable, null).getConstantState())
{...}
?ボタンの背景に特定のドロウアブルが割り当てられているかどうかを確認するための他の方法(API 21以上と互換性があります)はありますか?
ps:私のminsdkは21ですが、Lintは私に警告を与えていません。
それは働きました。理由は何ですか?助けてくれてありがとう! –
https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat.html#getDrawable(android.content.res)からResourceCompatの問題を確認することはできません。 Resources、int、android.content.res.Resources.Theme)は、 'getDrawable(resource)'と同じです。しかし、 'ResourcesCompat.getDrawable(getResources()、R.drawable.myDrawable、null).getConstantState()'を使うと、Android Studioはnullを返すことがあると不平を言います。したがって、問題が生じる。 –