Android Api Demos学习之Activity Dialog
此处的dilog并非是个view控件。demo里的一句话如是说:
This demonstrates the how to write an activity that looks like a pop-up dialog.
所以我么知道,这里只是将一个activity写成了dialog的形式。那么该如何去写呢?
public class DialogActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.dialog);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);
}
}
这几行代码里并不会实现效果,这里只是为title增加了一张图片,R.layout.dialog就是自定义view,放你想要的东西。最关键的实在mainfest.xml里。为这个activity增加了一个Dialog的主题:
<activity android:name="DialogActivity" android:theme="@android:style/Theme.Dialog" android:label="@string/clock"></activity>
显示的效果为: