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)入和退出的動(dòng)畫(huà) -->
<item name="android:windowAnimationStyle">@style/BottomDialogAnimation</item>
</style>
<!-- 進(jìn)入和退出的動(dòng)畫(huà) -->
<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í)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- Android自定義Dialog的2種常見(jiàn)方法
- Android自定義Dialog框樣式
- Android自定義Dialog原理實(shí)例解析
- Android 自定義加載動(dòng)畫(huà)Dialog彈窗效果的示例代碼
- Android自定義底部彈出框ButtomDialog
- android自定義Dialog彈框和背景陰影顯示效果
- Android自定義Dialog實(shí)現(xiàn)通用圓角對(duì)話框
- Android 自定義Dialog去除title導(dǎo)航欄的解決方法
- Android自定義Dialog實(shí)現(xiàn)加載對(duì)話框效果
- Android編程自定義AlertDialog樣式的方法詳解
- 解決Android中自定義DialogFragment解決寬度和高度問(wèn)題
- Android?自定義?Dialog?實(shí)現(xiàn)列表?單選、多選、搜索功能
相關(guān)文章
Java4Android開(kāi)發(fā)教程(五)java的基本數(shù)據(jù)類(lèi)型特征
這篇文章主要介紹了Java4Android開(kāi)發(fā)教程的第五篇文章java的基本數(shù)據(jù)類(lèi)型特征,需要的朋友可以參考下2014-10-10
Android+SQLite數(shù)據(jù)庫(kù)實(shí)現(xiàn)的生詞記事本功能實(shí)例
這篇文章主要介紹了Android+SQLite數(shù)據(jù)庫(kù)實(shí)現(xiàn)的生詞記事本功能,結(jié)合具體實(shí)例形式分析了Android操作SQLite數(shù)據(jù)庫(kù)實(shí)現(xiàn)生詞記錄功能的操作步驟與相關(guān)注意事項(xiàng),需要的朋友可以參考下2017-09-09
Android下拉刷新SwipeRefreshLayout控件使用方法
這篇文章主要介紹了Android下拉刷新SwipeRefreshLayout控件使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11
學(xué)習(xí)Android自定義Spinner適配器
這篇文章主要為大家詳細(xì)介紹了學(xué)習(xí)Android自定義Spinner適配器的相關(guān)資料,感興趣的小伙伴們可以參考一下2016-05-05
Android項(xiàng)目實(shí)現(xiàn)黑名單攔截效果
本篇文章主要介紹了Android項(xiàng)目實(shí)現(xiàn)黑名單攔截效果,可以根據(jù)白名單或者黑名單攔截,測(cè)試可以攔截電話,有需要的朋友可以了解一下。2016-10-10
Android開(kāi)發(fā)技巧之在a標(biāo)簽或TextView控件中單擊鏈接彈出Activity(自定義動(dòng)作)
a標(biāo)簽以及TextView自動(dòng)識(shí)別的特殊文本(網(wǎng)址、電話號(hào)、Email等),這些都可以通過(guò)單擊來(lái)觸發(fā)不同的動(dòng)作;但如果讀者想在單擊鏈接時(shí)執(zhí)行任意自定義的動(dòng)作,那么將要介紹的一定是你想要的了2013-01-01
android自定義Toast設(shè)定顯示時(shí)間
這篇文章主要為大家詳細(xì)介紹了android自定義Toast設(shè)定顯示時(shí)間,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08
Android五種隱藏狀態(tài)欄和標(biāo)題欄的方法
這篇文章主要介紹了Android五種隱藏狀態(tài)欄和標(biāo)題欄的方法的相關(guān)資料,需要的朋友可以參考下2017-05-05

