最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android Kotlin 實(shí)現(xiàn)底部彈框日歷組件的案例

 更新時(shí)間:2024年08月02日 10:55:54   作者:代碼x手莓莓  
這篇文章主要介紹了Android Kotlin 實(shí)現(xiàn)底部彈框日歷組件的案例,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

需求

如下圖所示, 底部彈出日歷組件
原生插件使用的有一個(gè)好處是可以根據(jù)你的系統(tǒng)語(yǔ)言切換插件內(nèi)的語(yǔ)言, 剛好我們這個(gè)app面向的國(guó)外用戶(hù), 而產(chǎn)品對(duì)日歷組件的日期顯示有特別要求, 因此這無(wú)疑減少了我們切換語(yǔ)言的開(kāi)發(fā)工作量

代碼

1. custom_bottom_datepicker.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#98ADABAB">
    <RelativeLayout
        android:id="@+id/dialog_bottom"
        android:layout_width="match_parent"
        android:layout_height="320dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/rounded_button_white"
        android:padding="20dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="40dp">
            <TextView
                android:id="@+id/cancel"
                android:layout_width="0dp"
                android:layout_weight="1.5"
                android:layout_height="38dp"
                android:layout_gravity="center_horizontal"
                android:text="Cancel"
                android:textAllCaps="false"
                android:textColor="@color/colorPrimary"
                android:textSize="14sp"
                android:gravity="center"
                />
            <TextView
                android:id="@+id/title"
                android:layout_width="0dp"
                android:layout_weight="5"
                android:layout_height="38dp"
                android:layout_gravity="center_horizontal"
                android:text="Date of Birth"
                android:textAllCaps="false"
                android:textColor="@color/colorPrimary"
                android:textSize="16sp"
                android:gravity="center"
                />
            <TextView
                android:id="@+id/save"
                android:layout_width="0dp"
                android:layout_weight="1.5"
                android:layout_height="38dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="139dp"
                android:text="Save"
                android:textAllCaps="false"
                android:gravity="center"
                android:textColor="@color/colorPrimary"
                android:textSize="14sp" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:gravity="center_horizontal"
            android:orientation="vertical">
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="5dp">
				// 這個(gè)是最關(guān)鍵的
                <DatePicker
                    android:id="@+id/dp_date"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:calendarViewShown="false"
                    android:datePickerMode="spinner"
                    />
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>

2. Activity.kt

import java.util.Date
/**
 * 個(gè)人信息頁(yè)
 */
class PersonnalInfoActivity : AppCompatActivity() {
    private var year: String? = null
    private var month: String? = null
    private var day: String? = null
    @RequiresApi(Build.VERSION_CODES.N)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_personal_info)
        birthday.setOnClickListener {
            chooseBirthFun()
        }
    }
    private fun chooseBirthFun() = run {
        val userInfo = SharedPrefs.loadUserFromPreferences(this@PersonnalInfoActivity)
        val view = layoutInflater.inflate(R.layout.custom_bottom_datepicker, null)
        val popupWindow = PopupWindow(
            view,
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT,
            true
        )
        // 設(shè)置PopupWindow是否能響應(yīng)外部點(diǎn)擊事件
        popupWindow.isOutsideTouchable = true
        // 設(shè)置PopupWindow是否能響應(yīng)點(diǎn)擊事件
        popupWindow.isTouchable = true
        // 設(shè)置PopupWindow彈出窗體的背景
        popupWindow.setBackgroundDrawable(
            ColorDrawable(
                ContextCompat.getColor(
                    this,
                    android.R.color.transparent
                )
            )
        )
        // 設(shè)置PopupWindow從底部彈出
        popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0)
        val save = view.findViewById<TextView>(R.id.save)
        val cancel = view.findViewById<TextView>(R.id.cancel)
        val dpDate = view.findViewById<DatePicker>(R.id.dp_date);
        // 設(shè)置默認(rèn)日期
        if (userInfo != null) {
            if (userInfo.birthday == "") {
                dpDate.init(1970, 0, 1, null);
            } else {
                year?.let {
                    (month)?.let { it1 ->
                        day?.let { it2 ->
                            dpDate.init(
                                it.toInt(),
                                (it1.toInt()) - 1,
                                it2.toInt(),
                                null
                            )
                        }
                    }
                };
            }
        }
        save.setOnClickListener {
            if (popupWindow.isShowing) {
                year = dpDate.getYear().toString()
                month = ((dpDate.getMonth() + 1).toString())
                day = dpDate.getDayOfMonth().toString()
                val birthStr = "${year}-${month}-${day}"
                // 此處可以處理選擇好的日期
                popupWindow.dismiss()
            }
        }
        cancel.setOnClickListener {
            if (popupWindow.isShowing) {
                popupWindow.dismiss()
            }
        }
    }
}

完成~

到此這篇關(guān)于Android Kotlin 實(shí)現(xiàn)底部彈框日歷組件的文章就介紹到這了,更多相關(guān)Android Kotlin底部彈框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳解用RxJava實(shí)現(xiàn)事件總線(Event Bus)

    詳解用RxJava實(shí)現(xiàn)事件總線(Event Bus)

    本篇文章主要介紹了用RxJava實(shí)現(xiàn)事件總線(Event Bus),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-11-11
  • android實(shí)現(xiàn)單選按鈕功能

    android實(shí)現(xiàn)單選按鈕功能

    這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)單選按鈕功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-05-05
  • 使用TransitionDrawable實(shí)現(xiàn)多張圖片淡入淡出效果

    使用TransitionDrawable實(shí)現(xiàn)多張圖片淡入淡出效果

    這篇文章主要為大家詳細(xì)介紹了使用TransitionDrawable實(shí)現(xiàn)多張圖片淡入淡出效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-08-08
  • Android在JNI中使用ByteBuffer的方法

    Android在JNI中使用ByteBuffer的方法

    這篇文章主要介紹了Android在JNI中使用ByteBuffer的方法,涉及Android中緩沖區(qū)的相關(guān)使用技巧,需要的朋友可以參考下
    2015-04-04
  • 從源代碼分析Android Universal ImageLoader的緩存處理機(jī)制

    從源代碼分析Android Universal ImageLoader的緩存處理機(jī)制

    這篇文章主要介紹了從源代碼分析Android Universal ImageLoader的緩存處理機(jī)制 的相關(guān)資料,需要的朋友可以參考下
    2016-01-01
  • 實(shí)例講解Android中的AutoCompleteTextView自動(dòng)補(bǔ)全組件

    實(shí)例講解Android中的AutoCompleteTextView自動(dòng)補(bǔ)全組件

    AutoCompleteTextView組件被用在輸入框中能實(shí)現(xiàn)輸入內(nèi)容自動(dòng)補(bǔ)全的功能,類(lèi)似于大家平時(shí)用Google時(shí)的輸入聯(lián)想,這里我們來(lái)用實(shí)例講解Android中的AutoCompleteTextView自動(dòng)補(bǔ)全組件,特別是實(shí)現(xiàn)郵箱地址補(bǔ)全的例子,非常實(shí)用
    2016-05-05
  • AndroidQ分區(qū)存儲(chǔ)權(quán)限變更及適配的實(shí)現(xiàn)

    AndroidQ分區(qū)存儲(chǔ)權(quán)限變更及適配的實(shí)現(xiàn)

    這篇文章主要介紹了AndroidQ分區(qū)存儲(chǔ)權(quán)限變更及適配的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • 深入理解Activity之間的數(shù)據(jù)傳遞

    深入理解Activity之間的數(shù)據(jù)傳遞

    本篇文章是對(duì)Activity之間的數(shù)據(jù)傳遞進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • Android常用的intent action匯總

    Android常用的intent action匯總

    這篇文章主要介紹了Android常用的intent action功能與用法,分析了intent的原理以及action屬性常用動(dòng)作名稱(chēng)、作用與使用方法,需要的朋友可以參考下
    2016-10-10
  • Android 高仿QQ圖片選擇器

    Android 高仿QQ圖片選擇器

    這篇文章主要介紹了Android 高仿QQ圖片選擇器的實(shí)現(xiàn)思路,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧
    2016-09-09

最新評(píng)論

永安市| 施秉县| 孟津县| 墨脱县| 邻水| 交口县| 巴林右旗| 洛扎县| 县级市| 南川市| 桂林市| 杭州市| 孝义市| 邯郸县| 石棉县| 克山县| 彭泽县| 得荣县| 蒲江县| 江津市| 孝昌县| 赫章县| 长寿区| 炎陵县| 萨嘎县| 当雄县| 石林| 乌审旗| 武强县| 襄垣县| 和平区| 北安市| 苏州市| 屯留县| 得荣县| 巴彦淖尔市| 卓资县| 绵竹市| 义乌市| 深泽县| 嫩江县|