-1
A
回答
3
MainActivity類別
Button openAlert;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
openAlert = (Button)findViewById(R.id.openAlert);
openAlert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
View alertView = getLayoutInflater().inflate(R.layout.custom_alert, null);
//Set the view
alert.setView(alertView);
//Show alert
final AlertDialog alertDialog = alert.show();
//Can not close the alert by touching outside.
alertDialog.setCancelable(false);
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
ImageView closeButton = (ImageView) alertView.findViewById(R.id.closeButton);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
}
});
}
MainActivity XML - >這是剛剛打開的警報
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.vzw.www.multviewalert.MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="OPEN ALERT"
android:id="@+id/openAlert"/>
</RelativeLayout>
您需要創建警報
自定義佈局按鈕custom_alert.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/alertContainer"
android:background="@drawable/custom_alert_bg">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/rowOne">
<ImageView
android:id="@+id/rowOneButtonOne"
android:background="#cdcdcd"
android:layout_margin="4dp"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="0.33"
/>
<ImageView
android:id="@+id/rowOneButtonTwo"
android:background="#cdcdcd"
android:layout_margin="4dp"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="0.33"
/>
<ImageView
android:id="@+id/rowOneButtonThree"
android:background="#cdcdcd"
android:layout_margin="4dp"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="0.33"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/rowTwo"
android:layout_below="@id/rowOne">
<ImageView
android:id="@+id/rowTwoButtonOne"
android:background="#cdcdcd"
android:layout_margin="4dp"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="0.33"
/>
<ImageView
android:id="@+id/rowTwoButtonTwo"
android:background="#cdcdcd"
android:layout_margin="4dp"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="0.33"
/>
<ImageView
android:id="@+id/rowTwoButtonThree"
android:background="#cdcdcd"
android:layout_margin="4dp"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="0.33"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/rowThree"
android:layout_below="@id/rowTwo">
<ImageView
android:id="@+id/rowThreeButtonOne"
android:background="#cdcdcd"
android:layout_margin="4dp"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="0.33"
/>
<ImageView
android:id="@+id/rowThreeButtonTwo"
android:background="#cdcdcd"
android:layout_margin="4dp"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="0.33"
/>
<ImageView
android:id="@+id/rowThreeButtonThree"
android:background="#cdcdcd"
android:layout_margin="4dp"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="0.33"
/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
<ImageView
android:id="@+id/closeButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_weight="0.33"
android:background="#cdcdcd" />
</RelativeLayout>
下面是警報背景繪製 custom_alert_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#ffffff"/>
<corners
android:radius="5dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
這將產生以下
這是一個骨架....你必須用圖像填充它們,然後點擊每個聽衆。
另外,如果你想向下移動的頂部。您可以在custom_alert.xml添加
android:layout_marginTop="50dp"
到alertContainer ID
相關問題
- 1. 多個警告對話框
- 2. 定製確認並警告對話框
- 3. 包含兩個Caliburn.Micro視圖的對話框視圖?
- 4. 製作全屏警告對話框
- 5. jqGrid警告對話框
- 6. 在警告對話框
- 7. 安卓:警告對話框
- 8. libGDX警告對話框
- 9. 定製警告對話框未定義的方法
- 10. 警告:無視多餘的面膜對話框條目:
- 11. 看一個警告對話框
- 12. 與列表視圖多個警報對話框
- 13. 填充警告對話框與列表視圖,JSON
- 14. 會話超時警告對話框MVC
- 15. 定製警告對話框尋找怪異在Android 4.x的
- 16. 多個視圖不會顯示在自定義警報對話框中
- 17. 如何定義的視圖中的警告對話框的位置
- 18. dealloc的一個視圖 - 控制警告
- 19. 如何將默認警告圖標包含到圖片框中
- 20. 彈出包含多個文本框的對話框
- 21. MVC 2 - 顯示包含局部視圖的jQuery對話框
- 22. 警告對話框不會爲列表
- 23. 警告對話框不IllegalStateException異常
- 24. 如何從警告對話框
- 25. 重寫JavaScript警告jQuery的對話框
- 26. 警告對話框顯示按鈕
- 27. 確認對話框(警告)提交
- 28. 警告對話框犯規拿出
- 29. 訪問按鈕的警告對話框
- 30. BB對話框顯示之前警告
請解釋一下你嘗試過什麼具體的你遇到的問題。 – CommonsWare