Android Setting设置中添加上一步按钮

需求

由于系统屏蔽了按键已经下拉功能,需要在进入Setting后返回

效果

实现效果如下图:

分析

Android 系统中已经添加了上一步下一步按钮,因此只需根据需求打开即可


patch

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
diff --git a/packages/apps/Settings/src/com/android/settings/SettingsActivity.java b/packages/apps/Settings/src/com/android/settings/SettingsActivity.java
index afcb85e..9b66681 100644 (file)
--- a/packages/apps/Settings/src/com/android/settings/SettingsActivity.java
+++ b/packages/apps/Settings/src/com/android/settings/SettingsActivity.java
@@ -574,9 +574,10 @@ public class SettingsActivity extends SettingsDrawerActivity
}
}

- setContentView(mIsShowingDashboard ?
- R.layout.settings_main_dashboard : R.layout.settings_main_prefs);
+ // setContentView(mIsShowingDashboard ?
+ // R.layout.settings_main_dashboard : R.layout.settings_main_prefs);

+ setContentView(R.layout.settings_main_prefs);
mContent = (ViewGroup) findViewById(R.id.main_content);

getFragmentManager().addOnBackStackChangedListener(this);
@@ -655,7 +656,7 @@ public class SettingsActivity extends SettingsDrawerActivity
}

// see if we should show Back/Next buttons
- if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
+ // if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {

View buttonBar = findViewById(R.id.button_bar);
if (buttonBar != null) {
@@ -675,38 +676,43 @@ public class SettingsActivity extends SettingsDrawerActivity
finish();
}
});
- mNextButton = (Button)findViewById(R.id.next_button);
- mNextButton.setOnClickListener(new OnClickListener() {
- public void onClick(View v) {
- setResult(RESULT_OK, getResultIntentData());
- finish();
- }
- });
-
- // set our various button parameters
- if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
- String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
- if (TextUtils.isEmpty(buttonText)) {
- mNextButton.setVisibility(View.GONE);
- }
- else {
- mNextButton.setText(buttonText);
- }
- }
- if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
- String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
- if (TextUtils.isEmpty(buttonText)) {
- backButton.setVisibility(View.GONE);
- }
- else {
- backButton.setText(buttonText);
- }
- }
+ mNextButton = (Button)findViewById(R.id.next_button);
+ mNextButton.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ setResult(RESULT_OK, getResultIntentData());
+ finish();
+ }
+ });
+
+ // set our various button parameters
+/*
+ * if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
+ * String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
+ * if (TextUtils.isEmpty(buttonText)) {
+ * mNextButton.setVisibility(View.GONE);
+ * }
+ * else {
+ * mNextButton.setText(buttonText);
+ * }
+ * }
+ * if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
+ * String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
+ * if (TextUtils.isEmpty(buttonText)) {
+ * backButton.setVisibility(View.GONE);
+ * }
+ * else {
+ * backButton.setText(buttonText);
+ * }
+ * }
+ *
+ */
+ mNextButton.setVisibility(View.GONE);
+ backButton.setText("上一步");
if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
skipButton.setVisibility(View.VISIBLE);
}
}
- }
+ // }

if (DEBUG_TIMING) Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
+ " ms");
您的支持将鼓励我继续创作!