【发布时间】:2017-08-30 18:45:24
【问题描述】:
我正在使用 .java 实现 surfaceView 以使用画布在屏幕上绘制,而不是使用 .xml 布局文件,但我想知道是否在某个时候(当我在视图中所做的工作完成时)可以将此视图与布局文件关联或调用按钮或alerdialog。
更清楚地说,例如当您在游戏中获胜或失败时会显示“您输了”或类似的警报对话框。
Main_Activity 看起来像:
public class Main extends Activity {
activity_layout_animation animation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
animation = new activity_layout_animation(this);
setContentView(animation);
}
@Override
protected void onPause(){
super.onPause();
animation.pause();
}
@Override
protected void onResume(){
super.onResume();
animation.resume();
}
视图文件的一些代码:
public class activity_layout_animation extends SurfaceView implements Runnable {
boolean CanDraw = false
public activity_layout_animation(Context context){
super(context);
surfaceHolder = getHolder();
}
@Override
public void run(){
while(CanDraw){
if ( !surfaceHolder.getSurface().isValid()){
continue;
}
}
}
编辑:我可以像这样添加一些东西:
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(context);
}
builder.setTitle("Delete entry")
.setMessage("Are you sure you want to delete this entry?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
但它只适用于public activity_layout_animation(Context context){,我想将它添加到run()
【问题讨论】:
-
AlertDialog 应该可以正常工作,无论是从 xml 加载内容视图,还是在代码中创建内容。您尝试调用 AlertDialog 了吗?
标签: android canvas android-alertdialog