我是 android 新手,当我单击该按钮时,我有一个按钮,它会显示一个弹出菜单。
它有两个项目白天和黑夜。
当我按下夜间按钮时,整个活动主题变为黑色,文本颜色为白色,我按下白天按钮,其变为白色,文本颜色为黑色。
我有一个代码,但它只改变他们的弹出菜单。
我怎样才能改变我的活动他们。
我的代码:
first class
btn_mode = (Button) findViewById(R.id.btn_content_mode);
btn_mode.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("bfr calling popup class");
PopupMenu_Mode popup_mode=new PopupMenu_Mode(context, btn_mode);
popup_mode. Popup_Menu();
//call_popupMode();
}
});
second class
public class PopupMenu_Mode extends Activity {
PopupMenu popup_Mode;
Context context;
Button b;
Activity activity;
public PopupMenu_Mode(Context context, Button btn_mode) {
// TODO Auto-generated constructor stub
this.b = btn_mode;
this.context = context;
}
public void Popup_Menu() {
// TODO Auto-generated constructor stub
System.out.println("inside popup mode class");
popup_Mode = new PopupMenu(context, b);
popup_Mode.getMenuInflater().inflate(R.menu.mode, popup_Mode.getMenu());
System.out.println("show popup mode ");
popup_Mode.show();
popup_Mode.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// TODO Auto-generated method stub
try {
switch (item.getItemId()) {
case R.id.day:
context.setTheme(R.style.AppThemeLight);
// l.setBackgroundColor(R.style.AppThemeDark);
break;
case R.id.night:
context.setTheme(R.style.AppThemeDark);
default:
break;
}
} catch (Exception e) {
// TODO: handle exception
Toast.makeText(getApplicationContext(), "nothing",
Toast.LENGTH_LONG).show();
}
return false;
}
});
}
}
样式.xml
<style name="AppThemeLight" parent="android:Theme.Holo.Light">
<item name="android:background">@color/white</item>
<item name="android:textColor">#000000</item>
</style>
<style name="AppThemeDark" parent="android:Theme.Holo">
<item name="android:background">@color/black</item>
<item name="android:textColor">#FFFFFF</item>
</style>