我无法将信息从surfaceView类发送到其父类
叠加活动将其视图设置为绘图面板:
public class Overlay extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_Overlay);
drawingPanel dPanel = new drawingPanel(this);
setContentView(dPanel);
}
}
然后在绘图板中:
public class drawingPanel extends SurfaceView implements SurfaceHolder.Callback {
Context context = context;
public Player(Context context, int num) throws ClassNotFoundException, IOException {
super(context);
this.context = context;
SurfaceHolder holder = getHolder();
holder.addCallback(this);
}
public boolean onTouchEvent(MotionEvent e){
if(e.getAction()==MotionEvent.ACTION_DOWN){
//send info to Overlay that drawingPanel was touched
}
}
}
触摸surfaceView时,我想将该信息发送到叠加层。我不能简单地在Overlay活动中使用onTouchEvent,因为我需要使用drawingPanel绘制内容。我的主要目标是在使用surfaceView时触摸屏幕时隐藏/显示操作栏。如果还有其他方法可以实现,请在下面说明。
答案 0 :(得分:1)
尝试将此行添加到onCreate
类
Overlay
方法中
dPanel.setActivity(this);
在setActivity()
类中实现drawingPanel
,如下所示:
public void setActivity(Activity overlayActivity) {
mActivity = overlayActivity;
}
这样,您可以使用mActivity
来引用您的Activity并调用公共方法来“隐藏/显示操作栏”,例如:
mActivity.getActionBar().hide();
和
mActivity.getActionBar().show();