我已经写在OnCreate以下code()Activity类的方法
I have write the following code in the onCreate() method of Activity class
Button btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0;
getWindow().setAttributes(params);
Toast.makeText(v.getContext(),"Button Clicked",Toast.LENGTH_LONG).show();
}
});
btn.performClick();
但问题是没有发生在按钮上点击的动作,但如果我点击该按钮后,这个动作被执行。
But the problem is that the action on the button click is not happened, but if I click on that button then this action is performed.
我想通过使用code锁定屏幕,但完全执行的onCreate()方法,
I want to lock the screen by using that code, but it locks after the full execution of onCreate() method,
任何想我怎么能做到这一点。
Any guess how i can do this.
试试这个
final Button backto_main = (Button) findViewById(R.id.back3x3);
backto_main.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//add your code here..
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0;
getWindow().setAttributes(params);
Toast.makeText(v.getContext(),"Button Clicked",Toast.LENGTH_LONG).show();
}
});