Android AlertDialog raises center position upward, Kotlin

Android AlertDialog raises the center position upward, Kotlin

    private fun show() {
        val view = LayoutInflater.from(this).inflate(android.R.layout.simple_list_item_1, null)
        val text = view.findViewById<TextView>(android.R.id.text1)
        text.text = "hello,world!"

        val dialog = AlertDialog.Builder(this)
            .setTitle("窗口")
            .setView(view)
            .create()

        val window: Window? = dialog.window
        window?.setGravity(Gravity.CENTER)

        val params: WindowManager.LayoutParams? = window?.attributes
        params?.height = 150
        params?.width = 300

        dialog.show()

        //此时,带有标题的窗口已经显示在屏幕正中心部位。

        //val metrics = windowManager.currentWindowMetrics
        //params?.height = 500//(metrics.bounds.height()*0.2).toInt() // 高度为屏幕的0.5
        //params?.width = 500//(metrics.bounds.width()*0.5).toInt() // 宽度为屏幕的0.6

        //更新位置,把窗口显示位置在正中心基础上提高500。
        params?.y = params?.y!! - 500
        dialog.onWindowAttributesChanged(params)
    }

Android Material Design: ListPopupWindow_listpopupwindow setting spacing-CSDN BlogThe article has been viewed 7k times. Android Material Design: ListPopupWindow The ListPopupWindow introduced by Android Material Design is first of all a PopupWindow, but this PopupWindow has a List embedded in it. Setting an Adapter for this List is equivalent to Android having a PopupWindows with a built-in ListView for developers. As shown in the figure: _listpopupwindow setting spacinghttps://blog.csdn.net/zhangphil/article/details/48900349Android DialogFragment (1)-CSDN BlogThe article has been viewed and read 2.2k times. Android DialogFragment (1) is similar to the past AlertDialog. The DialogFragment introduced by Android aims to provide developers with a "rich" dialog without having to be limited by the past Android AlertDialog. First of all, DialogFragment is a Fragment, which has all the properties and life cycle of Fragment. Secondly, DialogFragment has the same characteristics as AlertDihttps://blog.csdn.net/zhangphil/article/details/50886077< /span>https://blog.csdn.net/zhangphil/article/details/52448131The article has been viewed and read 3.3k times, liked 2 times, and collected 5 times.DialogFragment pops up at the bottom of the Android screen (3) The DialogFragment in appendix articles 1 and 2 is a regular DialogFragment, but in some current Android developments, it is often necessary to pop up a function dialog box from the bottom for the user to choose. There are also many open source projects for this kind of dialog box that pops up at the bottom, such as appendix articles 3, 4, 5, 6, 7, 8, 9, 10, 11. By transforming Android's native DialogFragment, you can also realize bottom pop-up of _dialogfragment bottom pop-upbottom of Android screen Pop-up DialogFragment (3)_dialogfragment Pop-up at the bottom-CSDN Bloghttps://blog.csdn.net/zhangphil/article/details/50923828The article has been viewed and read 1.6k times. Android DialogFragment (2) Appendix Article 1 briefly introduces how to implement a DialogFragment. This article introduces a simple method: directly overwriting DialogFragment's onCreateDialog to return an AlertDialog implementation dialog box. The example in this article is different from the appendix article 1: it no longer relies on onCreateView. Brief description of code running logic: The function is simple. When you click FloatingActionButtAndroid DialogFragment (2)-CSDN BlogThe article has been viewed 4.1k times. Write the code in onCreate: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_Android dialogfragment set full screenhttps://blog.csdn.net/zhangphil/article/details/52153424

Android PopupWindow-CSDN BlogThe article has been viewed and read 241 times. Code: package zhangphil.test;import android.content.Context;import android.content.res.Resources;import android.graphics.Color;import android.os.Bundle;import android.support.annotation.Nullable..._android popupwindow https://blog.csdn.net/zhangphil/article/details/82850102Android AlertDialog setView, kotlin-CSDN blogThe article has been viewed and read 487 times. Android DialogFragment (1) is similar to the past AlertDialog. The DialogFragment introduced by Android aims to provide developers with a "rich" dialog without having to be limited by the past Android AlertDialog. Android DialogFragment (2) Appendix Article 1 briefly introduces how to implement a DialogFragment. This article introduces a simple method: directly overwriting DialogFragment's onCreateDialog to return an AlertDialog implementation dialog box. https://blog.csdn.net/zhangphil/article/details/129951422

Guess you like

Origin blog.csdn.net/zhangphil/article/details/134990894