窗口形式的Activity看起来是这样:
其实,这与普通的Activity代码是一样的,只不过在AndroidManifest.xml中指定了Activity的themestyle为Dialog.Theme。
Activity代码仍然是这样:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class ThirdActivity extends Activity{
private Button btn = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.thrid);
this.btn = (Button) this.findViewById(R.id.thirdActivityBtn);
btn.setText(R.string.gotosecond);
this.btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(ThirdActivity.this, SecondActivity.class);
ThirdActivity.this.startActivity(intent);
}
});
}
}
AndroidManifest.xml中ThirdActivity的定义如下:
<activity
android:name=".ThirdActivity"
android:theme="@android:style/Theme.Dialog">
</activity>
这样Activity看起来就是一个窗口形式的Activity。