Android自定義dialog 自下往上彈出的實(shí)例代碼
具體代碼如下所示:
package com.example.idmin.myapplication.wiget;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import com.example.idmin.myapplication.R;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class BottomDialog extends Dialog {
@BindView(R.id.chang)
TextView chang;
@BindView(R.id.exite)
TextView exite;
@BindView(R.id.cancel)
TextView cancel;
private BottomDialogAlertListener listener;
private Object param;
private String text1;
private String text2;
private String cansleText;
public BottomDialog(Context context, BottomDialogAlertListener listener, Object param, String text1, String text2, String cansleText) {
super(context, R.style.dialog1);
this.listener = listener;
this.param = param;
this.text1 = text1;
this.text2 = text2;
this.cansleText = cansleText;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_bottom);
ButterKnife.bind(this);
setCancelable(false);
setCanceledOnTouchOutside(false);
if (listener != null) {
listener.onDialogCreate(this, param);
}
setView();
}
private void setView() {
chang.setText(text1);
exite.setText(text2);
cancel.setText(cansleText);
}
@OnClick({R.id.chang, R.id.exite, R.id.cancel})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.chang:
if (listener != null) {
listener.chenge(this,param);
}
break;
case R.id.exite:
if (listener != null) {
listener.excite(this,param);
}
break;
case R.id.cancel:
if (listener != null) {
listener.cancel(this,param);
}
break;
}
}
@Override
public void show() {
super.show();
/**
* 設(shè)置寬度全屏,要設(shè)置在show的后面
*/
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.gravity = Gravity.BOTTOM;
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
getWindow().getDecorView().setPadding(0, 0, 0, 0);
getWindow().setAttributes(layoutParams);
}
}
<!-- 自定義dialog樣式 -->
<style name="dialog1" parent="@android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:layout_width">match_parent</item>
<!-- 進(jìn)入和退出的動畫 -->
<item name="android:windowAnimationStyle">@style/BottomDialogAnimation</item>
</style>
<!-- 進(jìn)入和退出的動畫 -->
<style name="BottomDialogAnimation">
<!--進(jìn)入 -->
<item name="android:windowEnterAnimation">@anim/dialog_enter_from_bottom</item>
<!--退出-->
<item name="android:windowExitAnimation">@anim/dialog_exit_to_bottom</item>
</style>
<!--dialog_enter_from_bottom -->
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="200"
android:fromYDelta="100%p"
android:toYDelta="0"></translate>
</set>
<!--dialog_exit_to_bottom -->
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="200"
android:fromYDelta="0"
android:toYDelta="100%p"></translate>
</set>
總結(jié)
以上所述是小編給大家介紹的Android自定義dialog 自下往上彈出的實(shí)例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- Android自定義Dialog的2種常見方法
- Android自定義Dialog框樣式
- Android自定義Dialog原理實(shí)例解析
- Android 自定義加載動畫Dialog彈窗效果的示例代碼
- Android自定義底部彈出框ButtomDialog
- android自定義Dialog彈框和背景陰影顯示效果
- Android自定義Dialog實(shí)現(xiàn)通用圓角對話框
- Android 自定義Dialog去除title導(dǎo)航欄的解決方法
- Android自定義Dialog實(shí)現(xiàn)加載對話框效果
- Android編程自定義AlertDialog樣式的方法詳解
- 解決Android中自定義DialogFragment解決寬度和高度問題
- Android?自定義?Dialog?實(shí)現(xiàn)列表?單選、多選、搜索功能
相關(guān)文章
Android裁剪圖片為圓形圖片的實(shí)現(xiàn)原理與代碼
這個方法是根據(jù)傳入的圖片的高度(height)和寬度(width)決定的,如果是 width <= height時,則會裁剪高度,裁剪的區(qū)域是寬度不變高度從頂部到寬度width的長度2013-01-01
Android基于OpenCV實(shí)現(xiàn)Harris角點(diǎn)檢測
角點(diǎn)就是極值點(diǎn),即在某方面屬性特別突出的點(diǎn)。當(dāng)然,你可以自己定義角點(diǎn)的屬性(設(shè)置特定熵值進(jìn)行角點(diǎn)檢測)。角點(diǎn)可以是兩條線的交叉處,也可以是位于相鄰的兩個主要方向不同的事物上的點(diǎn)。本文介紹如何基于OpenCV實(shí)現(xiàn)Harris角點(diǎn)檢測2021-06-06
Android使用TabLayout+Fragment實(shí)現(xiàn)頂部選項(xiàng)卡
本文通過實(shí)例代碼給大家介紹了Android使用TabLayout+Fragment實(shí)現(xiàn)頂部選項(xiàng)卡功能,包括TabLyout的使用,感興趣的朋友參考下本文吧2017-05-05
Android?NDK入門初識(組件結(jié)構(gòu)開發(fā)流程)
這篇文章主要為大家介紹了Android?NDK入門之初識組件結(jié)構(gòu)開發(fā)流程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
Android實(shí)現(xiàn)繞球心旋轉(zhuǎn)的引導(dǎo)頁效果
本篇文章主要介紹了Android實(shí)現(xiàn)繞球心旋轉(zhuǎn)的引導(dǎo)頁效果,想要實(shí)現(xiàn)此效果的同學(xué)可以參考一下本文。2016-11-11
Android之PreferenceActivity應(yīng)用詳解(2)
看到很多書中都沒有對PreferenceActivity做介紹,而我正好又在項(xiàng)目中用到,所以就把自己的使用的在這總結(jié)一下,也方便日后查找2012-11-11
Android實(shí)現(xiàn)倒計(jì)時結(jié)束后跳轉(zhuǎn)頁面功能
最近在工作中遇到一個需求,需要在倒計(jì)時一段時間后進(jìn)行跳轉(zhuǎn)頁面,通過查找相關(guān)資料發(fā)現(xiàn)其中涉及的知識還不少,所以分享出來,下面這篇文章主要給大家介紹了關(guān)于Android實(shí)現(xiàn)倒計(jì)時結(jié)束后跳轉(zhuǎn)頁面功能的相關(guān)資料,需要的朋友可以參考下。2017-11-11

