summaryrefslogtreecommitdiff
path: root/core/java/android/preference/Preference.java
diff options
context:
space:
mode:
authorDoris Ling <dling@google.com>2017-03-20 13:33:45 -0700
committerDoris Ling <dling@google.com>2017-03-21 10:19:43 -0700
commit2cb4bab1a886dcab1cbca1b84382e65f16a8f177 (patch)
tree9e3aac3d1ca9ba3e2884c5a6e7cd1ed3226bfaa8 /core/java/android/preference/Preference.java
parent5beefa697aeca3eeaeeac50f781908657490e211 (diff)
Allow multi line preference title.
Add an attribute to Preference to specify whether single line is to be used for the preference Change-Id: I578b496cdc4c5b0e3b3146183c6c30c4dee02eab Fix: 36389770 Test: manual
Diffstat (limited to 'core/java/android/preference/Preference.java')
-rw-r--r--core/java/android/preference/Preference.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/core/java/android/preference/Preference.java b/core/java/android/preference/Preference.java
index d9c749a65d0f..4d14277be9c1 100644
--- a/core/java/android/preference/Preference.java
+++ b/core/java/android/preference/Preference.java
@@ -82,6 +82,7 @@ import java.util.Set;
* @attr ref android.R.styleable#Preference_defaultValue
* @attr ref android.R.styleable#Preference_shouldDisableView
* @attr ref android.R.styleable#Preference_recycleEnabled
+ * @attr ref android.R.styleable#Preference_singleLineTitle
*/
public class Preference implements Comparable<Preference> {
/**
@@ -133,6 +134,7 @@ public class Preference implements Comparable<Preference> {
private boolean mDependencyMet = true;
private boolean mParentDependencyMet = true;
private boolean mRecycleEnabled = true;
+ private boolean mSingleLineTitle = true;
/**
* @see #setShouldDisableView(boolean)
@@ -296,6 +298,10 @@ public class Preference implements Comparable<Preference> {
case com.android.internal.R.styleable.Preference_recycleEnabled:
mRecycleEnabled = a.getBoolean(attr, mRecycleEnabled);
break;
+
+ case com.android.internal.R.styleable.Preference_singleLineTitle:
+ mSingleLineTitle = a.getBoolean(attr, mSingleLineTitle);
+ break;
}
}
a.recycle();
@@ -597,6 +603,7 @@ public class Preference implements Comparable<Preference> {
if (!TextUtils.isEmpty(title)) {
titleView.setText(title);
titleView.setVisibility(View.VISIBLE);
+ titleView.setSingleLine(mSingleLineTitle);
} else {
titleView.setVisibility(View.GONE);
}
@@ -903,6 +910,27 @@ public class Preference implements Comparable<Preference> {
}
/**
+ * Sets whether to constrain the title of this Preference to a single line instead of
+ * letting it wrap onto multiple lines.
+ *
+ * @param singleLineTitle set {@code true} if the title should be constrained to one line
+ */
+ public void setSingleLineTitle(boolean singleLineTitle) {
+ mSingleLineTitle = singleLineTitle;
+ notifyChanged();
+ }
+
+ /**
+ * Gets whether the title of this preference is constrained to a single line.
+ *
+ * @see #setSingleLineTitle(boolean)
+ * @return {@code true} if the title of this preference is constrained to a single line
+ */
+ public boolean isSingleLineTitle() {
+ return mSingleLineTitle;
+ }
+
+ /**
* Returns a unique ID for this Preference. This ID should be unique across all
* Preference objects in a hierarchy.
*