您可以使用Dialog
並添加自己的自定義佈局,並控制它的每一個視圖的外觀。下面是一個例子你如何能做到這一點:
final Dialog alert = new Dialog(FingerPaintActivity.this, android.R.style.Theme_Light_Panel);
alert.requestWindowFeature(Window.FEATURE_NO_TITLE); // no title
alert.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation; // this is used for custom animation when dialog is showing and hiding
alert.setContentView(getLayoutInflater().inflate(R.layout.stamps, null)); // here is your custom layout
alert.getWindow().setLayout(width-50, (height-100)); // set height/width
,您可以使用組偵聽到的意見(例如按鈕)是這樣的:
Button myOkBtn = (Button) alert.findViewById(R.id.myOkBtn);
myOkBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
謝謝,這看起來非常有前途。所以,我沒有100%清楚的唯一的事情就是你的意思是'FingerPaintActivity.this',我假設FingerPaintActivity是啓動這個對話框(當前在前臺的Activity)的那個,那麼傳遞'this'與'FingerPaintActivity.this'? –
這是創建「對話框」所需的上下文。這段代碼被放在'OnClickListener'中,這就是爲什麼你不能只使用'this'並且我需要聲明'Activity's上下文。這就是原因。你只能在你的情況下使用'this'。 – hardartcore