我在android開發新的,所以我需要知道這是做彈出這樣的android系統完善,高效的方式,基本上在iOS中很容易使彈出和處理,但是如何下手,這是使用佈局或類似的東西,請參考我的鏈接或指南,以在Android上打開一個活動的彈出窗口。
回答
import android.app.*;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.*;
public class ShowPopUp extends Activity {
PopupWindow popUp;
LinearLayout layout;
TextView tv;
LayoutParams params;
LinearLayout mainLayout;
Button but;
boolean click = true;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
popUp = new PopupWindow(this);
layout = new LinearLayout(this);
mainLayout = new LinearLayout(this);
tv = new TextView(this);
but = new Button(this);
but.setText("Click Me");
but.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (click) {
popUp.showAtLocation(mainLayout, Gravity.BOTTOM, 10, 10);
popUp.update(50, 50, 300, 80);
click = false;
} else {
popUp.dismiss();
click = true;
}
}
});
params = new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
layout.setOrientation(LinearLayout.VERTICAL);
tv.setText("Hi this is a sample text for popup window");
layout.addView(tv, params);
popUp.setContentView(layout);
// popUp.showAtLocation(layout, Gravity.BOTTOM, 10, 10);
mainLayout.addView(but, params);
setContentView(mainLayout);
}
}
您可以使用上述代碼創建彈出式窗口。 –
嘗試PopupWindow;你可以看到一個例子here。
private PopupWindow pwindo;
private void initiatePopupWindow() {
try {
// We need to get the instance of the LayoutInflater
LayoutInflater inflater = (LayoutInflater) AndroidAudioPlayer.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.your_layout_Screen,
(ViewGroup) findViewById(R.id.popup_element));
pwindo = new PopupWindow(layout, 400, 600, true);
pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);
Button btnClosePopup = (Button) layout.findViewById(R.id.button);
btnClosePopup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pwindo.dismiss();
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
更多時尚和美觀警告對話框, 看看這個庫老古板的Sweet alert dialogs
請確認它是否免費使用。 –
是它的免費,其授權在麻省理工學院許可證https://github.com/pedant/sweet-alert-dialog#license – Veer3383
okkk謝謝親愛的。 –
您可以使用PopupWindow。
它被定義爲後某些事件發生或某些條款和 條件相匹配的是出現在活動前對 屏幕的窗口。此窗口通常用於顯示一些信息並提供控制來執行操作。彈出窗口 也有自己的GUI,必須在其內容視圖中進行設置。
private PopupWindow pw;
private void initiatePopupWindow() {
try {
//We need to get the instance of the LayoutInflater, use the context of this activity
LayoutInflater inflater = (LayoutInflater) ConfirmActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Inflate the view from a predefined XML layout
View layout = inflater.inflate(R.layout.popup_layout,
(ViewGroup) findViewById(R.id.popup_element));
// create a 300px width and 470px height PopupWindow
pw = new PopupWindow(layout, 300, 470, true);
// display the popup in the center
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
mResultText = (TextView) layout.findViewById(R.id.server_status_text);
Button cancelButton = (Button) layout.findViewById(R.id.end_data_send_button);
makeBlack(cancelButton);
cancelButton.setOnClickListener(cancel_button_click_listener);
} catch (Exception e) {
e.printStackTrace();
}
}
private OnClickListener cancel_button_click_listener = new OnClickListener() {
public void onClick(View v) {
pw.dismiss();
}
};
這裏,s可以幫助你: 佈局文件夾中創建一個XML名稱ccc.xml:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffee"
android:orientation="vertical"
android:theme="@style/AppTheme.NoActionBar"
>
<ImageView
android:layout_width="60dp"
android:layout_marginTop="100dp"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/check"
/>
<TextView
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:text="Invitaton Sent Sucessfully"
android:layout_gravity="center_horizontal"
android:textStyle="bold"
android:textSize="15dp"
/></LinearLayout>
然後寫你想要致電:
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialog d=new Dialog(MainActivity.this);
d.setContentView(R.layout.ccc);
d.show();
}
});
- 1. Android彈出窗口在彈出窗口外彈出時解僱
- 2. 在android中彈出窗口彈出窗口
- 3. Appium Android彈出
- 4. android:彈出菜單,彈出對話框
- 5. 在android中彈出的動畫
- 6. 在Android中定位彈出窗口
- 7. 在Android中使用alertdialog.builder彈出顯示
- 8. 在android中的彈出窗口大小
- 9. Android - 無法在片段中彈出
- 10. 在android中彈出圖像和音頻
- 11. 在Android中關閉彈出窗口
- 12. 在android中的彈出窗口?
- 13. 彈出在android中的微調框架
- 14. 在android中的彈出窗口
- 15. Android - Webview在彈出對話框中?
- 16. android彈出菜單
- 17. Android:彈出窗口
- 18. 彈出片段。 Android
- 19. Android彈出窗口
- 20. android彈出窗口
- 21. Android彈出消息
- 22. Android彈出箭頭
- 23. 在HTML中彈出雙彈出
- 24. 在JS中彈出數據彈出Python
- 25. 在joomla中彈出
- 26. 在Asp.net中彈出
- 27. 在OpenCL中彈出?
- 28. 在JQuery中彈出?
- 29. 在Android中使用彈出菜單實現OnItemLongClickListener到Android的ListView
- 30. Android studio Webview彈出窗口
請參閱https://stackoverflow.com/questions/2115758/how-to-display-alert-dialog-in-android。 – hypd09
這可能有助於瞭解這些想法:https://www.google.com/design/spec/components/dialogs.html#dialogs-simple-dialogs –