+)기록/과제

정리사항 6 - **설정창, Serializable상속(프레임 레이아웃과 설정창 연결 후 타이틀 설정), 기타 설정, 버전명 가져오기

AppJinny 2023. 2. 21. 09:07

* 인텐트 참고

https://yooniron.tistory.com/2

 

***설정창 프래그먼트 인텐트로 전달하고 받기

---주의 : 프래그먼트 클래스는 Serializable을 상속 받아야 함

프래그먼트에서 Serializable 인터페이스를 구현하여 객체를 직렬화(Serialization)할 수 있는 이유는 다음과 같습니다:

프래그먼트 간에 데이터 전달: 직렬화를 통해 객체를 바이트 스트림으로 변환하고 전달할 수 있습니다. 이를 통해 프래그먼트 간에 데이터를 전송하거나 인수로 전달할 수 있습니다. 예를 들어, 액티비티에서 프래그먼트로 데이터를 전달하거나, 한 프래그먼트에서 다른 프래그먼트로 데이터를 전달하는 등의 상황에서 사용될 수 있습니다.

상태 저장 및 복원: 직렬화를 통해 객체의 상태를 저장하고 나중에 복원할 수 있습니다. 프래그먼트는 화면 회전이나 사용자의 상호작용에 따라 상태가 변경될 수 있는데, 이를 처리하기 위해 프래그먼트의 상태를 저장하고 나중에 복원할 수 있어야 합니다. Serializable 인터페이스를 구현한 객체는 액티비티의 상태 저장 및 복원 메커니즘에 사용될 수 있습니다.

public class SetDeviceFragment extends PreferenceFragmentCompat implements Serializable {

 

*설정창 프래그먼트 클릭 시 화면 전환하면서 정보 인텐트 넘기기

case R.id.setDevice:
    String setDeviceTitle = binding.setDeviceTitle.getText().toString();
    intent.putExtra("title", setDeviceTitle);

    intent.putExtra("key", new SetDeviceFragment());
    break;

 

*전달받기

//전달받은 인텐트 값에따라 프래그먼트 연결
Intent intent = getIntent();
Serializable setIntent = intent.getSerializableExtra("key");

//프래그먼트 연결
getSupportFragmentManager()
        .beginTransaction()
        .replace(R.id.frameLayout, (Fragment) setIntent)
        .commit();

//전달받은 설정타이틀로 변경
binding.setTitleName.setText(intent.getStringExtra("title"));

 

*SwitchPreference 의 속성 중 온 되었을 때 하위 설정 활성화

이 부분은 CheckBox가 체크되면 활성화 되는 부분으로서, dependency 속성이 추가된다.

https://android-uni.tistory.com/7

 

[안드로이드] Setting Preference 사용하기 (Java)

SettingPreference *** Basis 오늘은 안드로이드 앱을 만들 때 자주 접하게 될 settingPreference에 대하여 정리했다. settingPreference는 Activity외에 다른 xml로 setting에 대한 메뉴를 먼저 정의해준다. 그 정의를 fr

android-uni.tistory.com

 

*SwitchPreference 의 속성 서머리 온오프 텍스트

android:summaryOff="Device MAC : 2C-D2-6B-C5-86-DB"
android:summaryOn="Custom MAC"

 

*동적 요약 업데이트 <EditTextPreference

app:useSimpleSummaryProvider="true"

 

https://developer.android.com/guide/topics/ui/settings/customize-your-settings?hl=ko#java 

 

설정 맞춤설정  |  Android 개발자  |  Android Developers

컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 설정 맞춤설정  Android Jetpack의 구성요소 이 주제에서는 계층 구조에서 Preferences를 맞춤설정하는 방법을 설

developer.android.com

 

*환경설정 구성요소

https://developer.android.com/guide/topics/ui/settings/components-and-attributes?hl=ko 

 

환경설정 구성요소 및 속성  |  Android 개발자  |  Android Developers

컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 환경설정 구성요소 및 속성   Android Jetpack의 구성요소. 이 주제에서는 가장 일반적으로 사용되는 Preference 구

developer.android.com

 

*환경설정 - EditTextPreference 다이얼로그 테마변경

-다이얼로그 포지티브, 네거티브 버튼 색상 기본 테마설정하여 변경

--변경 시 테마에서 새로 스타일 만들고 매니페스트에 적용함

-입력창은 따로 에디트텍스트 xml을 만들어서 사용하여 아래와 같이 적용

android:dialogLayout="@layout/preference_edit_text"

 

https://stackoverflow.com/questions/27912608/dialogfragment-buttons-color-change-in-lollipop

 

DialogFragment buttons color change in Lollipop

I would like my Fragments to look consistent with the rest of the app and color palette which I applied so I would like to change the colors not only of title, but also of positive/negative buttons...

stackoverflow.com

 

 

*환경설정 스위치(토글버튼) 색상변경

-테마에 아이템 추가 후 적용

<item name="colorControlActivated">@color/custom_setting_blue</item>

 

https://stackoverflow.com/questions/27845595/how-to-change-the-track-color-of-a-switchcompat

 

How to change the track color of a SwitchCompat

I've tried using the following link to change the color of a SwitchCompat: How to change the color of a SwitchCompat Notice the low constrast in my switch: But after changing all relevant color ...

stackoverflow.com

 

*설정창 선택창

-arrays에 새로 만들고 entries속성으로 적용 

<string-array name="ledModeOnSetting">
    <item>얼굴인식 시 On</item>
    <item>Always On</item>
</string-array>

<string-array name="ledModeOnSetting_values">
    <item>0</item>
    <item>1</item>
</string-array>

 

android:defaultValue="0"
android:entries="@array/ledModeOnSetting"
android:entryValues="@array/ledModeOnSetting_values"
android:negativeButtonText="@null"
android:positiveButtonText="@null"

 

-3번 리스트 프리퍼런스

https://velog.io/@changhee09/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-%EC%95%B1%EC%9D%98-%ED%99%98%EA%B2%BD%EC%84%A4%EC%A0%95-Preference

 

[안드로이드] 앱의 환경설정 - Preference

이 글은 깡썜의 안드로이드 프로그래밍을 보고 작성하였습니다. 틀린 부분을 댓글로 남겨주시면 수정하겠습니다..!! Preference 앱에서 환경설정을 위해 액티비티에서 설정 화면을 구성하고, 그 화

velog.io

 

*특수문자 유니코드 확인

-윈도우 실행창 - charmap 찾기

https://hw00173.tistory.com/35

 

[안드로이드] 안드로이드에서 특수 문자 입력하기.

안드로이드에서 가끔 특수문자를 입력하려면 유니코드를 사용해야지만 입력이 가능하다. 다음과 같이 Q&A 라는 텍스트를 입력하고자 할 때 다음과 같은 상황이 발생할 것이다. 이러한 문제를 해

hw00173.tistory.com

 

*설정창 다이얼로그 띄우기

https://copyprogramming.com/howto/how-do-you-show-a-dialogpreference

 

*버전명 가져오기

https://hydok.tistory.com/25

 

[안드로이드] 앱 버전명 및 버전코드 가져오기

앱 버전명 및 버전코드 가져오기 위와 같이 설정된 앱의 버전명과 버전코드를 가져오는 방법 입니다. PackageInfo pInfo = null; try { pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); } catch (PackageManager.

hydok.tistory.com