1、需求分析
眾所周知,在應(yīng)用中這樣那樣的評論總是少不了的,有的應(yīng)用是在底部直接加一個EditText和一個Button,讓用戶輸入文字或者表情之后點擊按鈕提交;而有的雖然也放置了EditText,但僅僅是一個“擺設(shè)”,并不具備輸入功能,用戶點擊它后會彈出一個跳轉(zhuǎn)到一個可以真正編輯的頁面或者彈出一個可以輸入內(nèi)容的對話框。
比如下面這種效果:

這里的效果可以細分為四點:
一開始我想到的是PopupWindow,但是由于里面有EditText,與軟鍵盤交互起來很是頭疼,于是改用了Activity。這樣一來我們就可以像用Activity一樣使用這個對話框,方便多了。不過畢竟跟我們平時使用的Activity還是有所不同的,特別是要設(shè)置好它的樣式,否則也是一堆的坑啊。
2、對話框Activity的布局與樣式
下面就來著手實現(xiàn)我們想要的對話框了。新建一個工程,MainActivity只是一個配角,底部放一個按鈕就搞定。我們的主角是DialogActivity,它的布局很簡單,就跟平時的Activity一樣:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_gravity="bottom" android:background="@android:color/white" android:orientation="vertical" android:paddingLeft="10dp" android:paddingRight="10dp"> <EditText android:id="@+id/et_comment" android:layout_width="match_parent" android:layout_height="150dp" android:layout_marginTop="15dp" android:background="#f0f0f0" android:focusable="true" android:focusableInTouchMode="true" android:gravity="left|top" android:hint="我 主站蜘蛛池模板: 周至县| 哈巴河县| 湖州市| 娱乐| 浮山县| 柳河县| 金沙县| 灵山县| 平舆县| 长武县| 天长市| 嘉禾县| 五华县| 田东县| 进贤县| 孙吴县| 广西| 共和县| 龙里县| 泽州县| 丰城市| 五峰| 阜宁县| 定结县| 盱眙县| 黑水县| 河北区| 宜阳县| 南溪县| 巨鹿县| 普陀区| 齐齐哈尔市| 久治县| 凯里市| 达州市| 博客| 且末县| 莆田市| 江油市| 贡觉县| 定西市|