Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android-检查android版本不工作的挫折_Android_Button_Background_Drawable - Fatal编程技术网

android-检查android版本不工作的挫折

android-检查android版本不工作的挫折,android,button,background,drawable,Android,Button,Background,Drawable,我想改变一个按钮的背景画。我的最小SDK版本是14。因此,我检查设备上安装的当前版本: int sdk = android.os.Build.VERSION.SDK_INT; if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { buttonClubPublic.setBackgroundDrawable(buttonClubPublic.getContext().getResources().getDrawable(R.dra

我想改变一个按钮的背景画。我的最小SDK版本是14。因此,我检查设备上安装的当前版本:

int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
    buttonClubPublic.setBackgroundDrawable(buttonClubPublic.getContext().getResources().getDrawable(R.drawable.check_button));
    buttonClubPrivate.setBackgroundDrawable(buttonClubPrivate.getContext().getResources().getDrawable(R.drawable.uncheck_button));
} else {
    buttonClubPublic.setBackground(buttonClubPublic.getContext().getResources().getDrawable(R.drawable.check_button));
    buttonClubPrivate.setBackground(buttonClubPrivate.getContext().getResources().getDrawable(R.drawable.uncheck_button));
}

按钮背景是动态的还是可以用XML设置?是否添加了支持库?如果答案是肯定的,那么它只是一个黄色警告,而不是红色警告,您可以抑制它。我在xml中设置了按钮如果您在xml中设置了按钮,则完全不需要在代码中重置它。您需要@SuppressLint'NewApi'注释
<Button
    android:id="@+id/create_club3_club_privat"
    android:text="@string/create_club3_privat"
    android:textColor="#000000"
    android:textSize="@dimen/check_button_size"
    android:layout_width="@dimen/check_button_width"
    android:layout_height="wrap_content"
    android:background="@drawable/uncheck_button"
    android:layout_marginLeft="@dimen/create_team_check_button_margin"
/>