3.19 全屏幕以按钮重写
动态产生按钮并最大化
问题2:Unable to add window -- token null is not for an application错误的解决方法
(更多请参考:http://blog.csdn.net/vipa1888/article/details/7034339)
package edu.cquptzx.FullScreenButton;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
publicclass FullScreenButtonActivity extends Activity
{
/** Called when the activity is first created. */
public ProgressDialog pd = null;
@Override
publicvoid onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/* Here we didn't use the main.xlm layout.Instead,we use a button as a layout add to the Activity.*/
/*这里我们不使用main.xml的布局,而是将按钮作为布局添加到活动中去.*/
//setContentView(R.layout.main);
Button btn = new Button(this);
this.setContentView(btn);
btn.setText(R.string.btn_text);
btn.setOnClickListener(
new Button.OnClickListener()
{
@Override
publicvoid onClick(View v)
{
CharSequence strDialogTitle = getString(R.string.strDialogTitle);
CharSequence strDialogBody = getString(R.string.strDialogBody);
/* 下面的方法的第一参数为context,
* 此处的context 要保证你的上下文要为activity对象,
* 只有activity才能添加ProgressDialog窗体,
* 为了确保正确,context可以使用activity.this表示,
* 不要一味地写成getApplicationContext()*/
/* 下面的种写法只有第一种正确.*/
pd = ProgressDialog.show(FullScreenButtonActivity.this, strDialogTitle , strDialogBody,true);
// pd = ProgressDialog.show(getApplicationContext(), strDialogTitle , strDialogBody,true);
//pd = ProgressDialog.show(getBaseContext(), strDialogTitle , strDialogBody,true);
new Thread()
{
publicvoid run()
{
try
{
sleep(3000);
}
catch( Exception e)
{
e.printStackTrace();
}
finally
{
pd.dismiss();
}
}
}.start();
}
}
);
}
}