TIL) 0914

Hanseul Lee·2022년 9월 14일
0

TIL

목록 보기
10/23
post-custom-banner

화면 이동하면서 EditTextView에 포커스 주기

화면이 시작했을 때 Focus를 줄 EditTextView의 xml에 다음과 같이 설정.

<EditText
        android:id="@+id/sign_in_email_edit"
        ...>
        <requestFocus />
    </EditText>

출발할 Fragment에서 키보드 올리기

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        setAdapter()

        binding.profileLogin.setOnClickListener {
            keyBoardUp()
            findNavController().navigate(R.id.action_profileFragment_to_signInFragment)
        }
    }

    private fun keyBoardUp() {
        val keyboardAutoUpload = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager

        keyboardAutoUpload.toggleSoftInput(
                InputMethodManager.SHOW_FORCED,
                InputMethodManager.HIDE_IMPLICIT_ONLY
        )
    }

도착한 Framgment에서 KeyListener를 활용해 키보드 내릴 때 코드 → Listener 처리 주의

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        binding.signInPwdEdit.setOnKeyListener(object : View.OnKeyListener {
            override fun onKey(v: View?, keyCode: Int, event: KeyEvent): Boolean {
                if (event.action != KeyEvent.ACTION_DOWN) {
                    return true
                }
                when (keyCode) {
                    KeyEvent.KEYCODE_ENTER -> {
                        keyBoardDown()
                    }
                }
                return true
            }
        })
    }

    private fun keyBoardDown() {
        val keyBoardDown = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        keyBoardDown.hideSoftInputFromWindow(binding.signInEmailEdit.windowToken, 0)
    }

Custom CheckBox

FragmentLayout XML

<CheckBox
        android:id="@+id/sign_in_auto_login_check"
        ...
        android:background="@drawable/custom_login_checkbox"
        android:button="@null"
        ... />
// custom_login_checkbox.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 체크박스 해제 상태 -->
    <item android:state_checked="false"
        android:drawable="@drawable/custom_login_checkbox_noncheck"/>
    <!-- 체크박스 선택 상태 -->
    <item android:state_checked="true"
        android:drawable="@drawable/custom_login_checkbox_check"/>
</selector>
// custom_login_checkbox_check.xml

<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <stroke android:width="3dp" android:color="@color/primaryLightColor" />
            <solid android:color="@color/white" />
            <corners android:radius="2dp" />
        </shape>
    </item>
    <item android:drawable="@drawable/ic_baseline_check_24" />
</layer-list>
// custom_login_checkbox_noncheck.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <stroke android:width="3dp" android:color="@color/primaryLightColor" />
            <solid android:color="@color/white" />
            <corners android:radius="2dp" />
        </shape>
    </item>
</selector>

부분 테두리

왼쪽을 제외하고 테두리를 만드는 코드. primaryColor로 색이 칠해지고, 테두리 색이 primaryLightColor다.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/primaryColor" />
        </shape>
    </item>
    <item
        android:left="1dp"
        android:top="1dp"
        android:bottom="1dp">
        <shape android:shape="rectangle">
            <solid android:color="@color/primaryLightColor" />
        </shape>
    </item>
</layer-list>
post-custom-banner

0개의 댓글