如何在用户单击按钮时创建图像按钮。我尝试了不同的解决方案,但没有帮单击按钮上的Android图像按钮显示
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OnClickListener oclBtnOK =new OnClickListener(){
public void onClick(View V) {
getImageButton();
}
private void getImageButton() {
ImageButton imgbtn = new ImageButton(null, null);
imgbtn.getContext();
}
};
button1.setOnClickListener(oclBtnOK);
}
您在Layout中添加ImageButton的位置? –
看看这里的答案http://stackoverflow.com/a/16417150/4384828 –
我没有在布局中添加imagebutton。如果我已经将它添加到布局中,那么它将直接显示在我的屏幕上,而不必单击按钮。 –