Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 1차원 DP
- 2차원 dp
- 99클럽
- @Builder
- @GeneratedValue
- @GenericGenerator
- @NoargsConstructor
- @Transactional
- Actions
- Amazon EFS
- amazon fsx
- Android Studio
- ANSI SQL
- ApplicationEvent
- assertThat
- async/await
- AVG
- AWS
- Azure
- bind
- builder
- button
- c++
- c++ builder
- c03
- Callback
- case when
- CCW
- chat GPT
- CICD
Archives
- Today
- Total
기록
androidStudio/java/preference:1.1.1 사용하기 본문
1. 종속성 추가
File>Project Structure (또는 gradle에 직접 추가)
2. root_preferences.xml
res>xml>root preferences.xml
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory app:title="계정">
<Preference
app:key="image"
app:title="프로필 이미지 변경" />
<Preference
app:key="nickname"
app:title="닉네임 변경" />
<Preference
app:key="logout"
app:title="로그 아웃" />
<Preference
app:key="signout"
app:title="회원 탈퇴"/>
</PreferenceCategory>
<PreferenceCategory app:title="앱정보">
<Preference
app:title="app_name"
app:summary=""/>
<Preference
app:title="프로젝트 소개"
app:summary=""/>
<Preference
app:key="opensource"
app:title="오픈소스 라이선스"/>
<Preference
app:key="feedback"
app:summary="Report technical issues or suggest new features"
app:title="피드백 보내기"/>
</PreferenceCategory>
</PreferenceScreen>
3. activity_setting.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:theme="@style/LightTheme">
<FrameLayout
android:id="@+id/setting_frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
4. SettingActivity.java
public class SettingActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setting);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.setting_frameLayout, new SettingsFragment())
.commit();
}
public static class SettingsFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceClickListener {
private Preference feedback;
private Preference logout;
private Preference signout;
private Preference opensource;
private Preference image;
private Preference nickname;
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);
feedback = findPreference("feedback");
logout = findPreference("logout");
signout = findPreference("signout");
opensource = findPreference("opensource");
image = findPreference("image");
nickname = findPreference("nickname");
feedback.setOnPreferenceClickListener(this);
logout.setOnPreferenceClickListener(this);
signout.setOnPreferenceClickListener(this);
opensource.setOnPreferenceClickListener(this);
image.setOnPreferenceClickListener(this);
nickname.setOnPreferenceClickListener(this);
}
// 클릭 이벤트 지정
@Override
public boolean onPreferenceClick(final Preference preference) {
switch (preference.getKey()) {
case "feedback":
return false;
case "logout":
return false;
case "signout":
return false;
case "opensource":
return false;
default:
return false;
}
}
}
}
실행결과
'Moblie > Android' 카테고리의 다른 글
androidStudio/Google Map API 사용하기 (0) | 2021.11.28 |
---|---|
androidStudio/localhost 서버 접속하기 (0) | 2021.06.07 |
androidStudio/실제 단말기를 이용하여 실행시키기 (0) | 2021.03.12 |
[issue] Caused-by-javalangBootstrapMethodError-Exception-from-call-site-4-bootstrap-method (0) | 2020.09.29 |
androidStudio/java/다른 앱으로 사용자 보내기 (0) | 2020.09.07 |
Comments