如何在用戶單擊按鈕時創建圖像按鈕。我嘗試了不同的解決方案,但沒有幫單擊按鈕上的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。如果我已經將它添加到佈局中,那麼它將直接顯示在我的屏幕上,而不必單擊按鈕。 –