在 android 更新可绘制图像运行时
updating drawable image runtime in android
我正在尝试更新 android 图片 onClick 它是在弹出窗口中动态创建的,如果我单击图片,则必须将图片替换为较小的尺寸图像的一部分,它将在加载片段后重定向到另一个片段资源必须变为正常大小我尝试使用以下代码。
if (MenuButton[0].getId() == v.getId()) {
MenuButton[0].setBackgroundResource(R.drawable.Small_menu_general); //updating here
myLog.v(TAG, Thread.currentThread().getStackTrace()[2].getLineNumber(), "Select Menu", "General Setting");
Product_Location(Vars.Menu_General);
GlobalClass.fragment = new Run_Screen();
getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.fade_in, 0, 0, R.anim.fade_out).replace(R.id.fragment_place, GlobalClass.fragment).commit();
HideMainMenu();
}
在 HideMainMenu() 中,我正在尝试将其更新为正常
public void HideMainMenu() {
Menu_Frame_1.clearAnimation();
Menu_Frame_1.startAnimation(Menu_Hide_Anim);
Menu_Frame_2.clearAnimation();
Menu_Frame_2.startAnimation(Menu_Hide_Anim);
Main_Menu.startAnimation(MenuHideRotation);
MenuButton[0].setBackgroundResource(R.drawable.Normal_menu_general); //retaining to normal here
}
你可以使用状态来实现这个
StateListDrawable states = new StateListDrawable();
states.addState(new int[] {android.R.attr.state_pressed},
getResources().getDrawable(R.drawable.Small_menu_general));
MenuButton[0].setImageDrawable(states);
我正在尝试更新 android 图片 onClick 它是在弹出窗口中动态创建的,如果我单击图片,则必须将图片替换为较小的尺寸图像的一部分,它将在加载片段后重定向到另一个片段资源必须变为正常大小我尝试使用以下代码。
if (MenuButton[0].getId() == v.getId()) {
MenuButton[0].setBackgroundResource(R.drawable.Small_menu_general); //updating here
myLog.v(TAG, Thread.currentThread().getStackTrace()[2].getLineNumber(), "Select Menu", "General Setting");
Product_Location(Vars.Menu_General);
GlobalClass.fragment = new Run_Screen();
getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.fade_in, 0, 0, R.anim.fade_out).replace(R.id.fragment_place, GlobalClass.fragment).commit();
HideMainMenu();
}
在 HideMainMenu() 中,我正在尝试将其更新为正常
public void HideMainMenu() {
Menu_Frame_1.clearAnimation();
Menu_Frame_1.startAnimation(Menu_Hide_Anim);
Menu_Frame_2.clearAnimation();
Menu_Frame_2.startAnimation(Menu_Hide_Anim);
Main_Menu.startAnimation(MenuHideRotation);
MenuButton[0].setBackgroundResource(R.drawable.Normal_menu_general); //retaining to normal here
}
你可以使用状态来实现这个
StateListDrawable states = new StateListDrawable();
states.addState(new int[] {android.R.attr.state_pressed},
getResources().getDrawable(R.drawable.Small_menu_general));
MenuButton[0].setImageDrawable(states);