preference

PreferenceActivity works properly on Android 2.1, but not 4.1 (padded)

独自空忆成欢 提交于 2019-12-10 15:11:45
问题 I'm writing an application. It needs to run on old android OS's to be useful. I have written the preferences screen using a PreferencesActivity that populates with a options.xml file that contains PreferenceScreen. It has no submenu for preferences (so PreferenceFragment provides no real benefits). In Android 2.1 (2.2 and 2.3, haven't tested on ICS yet) the screen displays properly like so in landscape: But on Jellybean, it looks like this: It looks terrible. I have nothing defined as a

Read SharedPreferences when you haven't set the name of the file

大城市里の小女人 提交于 2019-12-10 13:34:30
问题 When you createa a PreferenceScreen on Android, your application creates a default SharedPreferences file for the settings. I want to read this name, or get a reference without specifing the name. Currently I use: SharedPreferences prefs = ctx.getSharedPreferences("prefs", 0); SharedPreferences.Editor ed=prefs.edit(); But this returns another copy of the preference. When I checked the folder in /data/data/myapk/shared_prefs I see two files, one named prefs.xml and the other is my [package

How can I set the android preference summary text color?

纵然是瞬间 提交于 2019-12-09 14:05:52
问题 On my preference screen I have a preference that when clicked opens a color picker dialog. What I would like to do is when the user selects a color, that the text summary of the preference is displayed in that color. I know I can have the summary set up like this, Currently <font color="#ff0000">this color</font> and have it display in that color. The problem is the color I am getting back is the android int color. I could use the red(), green(), blue() methods and then convert those to Hex

How to instantiate layout for custom preference, using android:layout attribute

怎甘沉沦 提交于 2019-12-09 11:00:43
问题 I can set appropriate layout for preference through android:layout attribute. For an example <Preference android:key="friction" android:title="@string/friction" android:layout="@layout/friction_fragment" android:shouldDisableView="true" android:defaultValue="30" android:enabled="true" android:selectable="true" android:summary="Bite friction"> </Preference> where layout is <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android

can I make ringtone in preferences

白昼怎懂夜的黑 提交于 2019-12-08 09:14:48
问题 How can I make ringtone activity (that always appear in setting) so the user can choose her ringtone from system ringTones I googled it but I didn't find complete tutorial, I am really confused, please give me tutorial or some codes. Also, if I want the user to choose the special ringtone to Notification in my application should i use Shared preference or preference? I already did the Menu: // Menu Code Part#2 public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) {

Instantiating an inner class (Preference) in xml file

十年热恋 提交于 2019-12-06 21:19:12
问题 When you want to access a custom view in some layout.xml file, you have two options: The view is in it's own class. Then you do <package.name.MyView android:layout_width= ... /> The view is an inner class: <view class="package.name.OuterClass$MyView" android:layout_width= ... /> Now I want to do the same thing inside a <PreferenceScreen> . The first way works well, but I would like to put all the custom Preference classes together in my PreferenceActivity. I tried <Preference class="package

How to validate an EditTextPreference value for a specific int range

拥有回忆 提交于 2019-12-06 09:15:13
问题 I want to validate an EditTextPreference value to be inside a specific int range (lets say 1 to 22). The only part that I could validate was the inputType (number only) with the following xml declaration in the prefs.xml file. android:inputType="number" The second thing that I did is to write the following code in the ListSettings activity. public class ListSettings extends PreferenceActivity implements OnSharedPreferenceChangeListener{ @Override public void onCreate(Bundle savedInstanceState

Converting string to uri to bitmap to display in an ImageView

余生颓废 提交于 2019-12-05 06:39:27
问题 I have looked all over for a solution to my problem and just can't seem to figure it out. I'm sure it is probably 1 or 2 simple lines and hopefully someone can steer me in the right direction. In my app, a user can click a button that will open the gallery. Once they select an image, it will display that image in an ImageView within my app. That part is working perfectly fine. Originally, I just had it return a uri from the gallery and I would directly display that with this: imageView1

Instantiating an inner class (Preference) in xml file

时光总嘲笑我的痴心妄想 提交于 2019-12-05 02:13:05
When you want to access a custom view in some layout.xml file, you have two options: The view is in it's own class. Then you do <package.name.MyView android:layout_width= ... /> The view is an inner class: <view class="package.name.OuterClass$MyView" android:layout_width= ... /> Now I want to do the same thing inside a <PreferenceScreen> . The first way works well, but I would like to put all the custom Preference classes together in my PreferenceActivity. I tried <Preference class="package.name.OuterClass$MyPreference" ... /> (also with '.' instead of '$') as well as <package.name.OuterClass

订制属于你自己的PreferenceActivity

孤者浪人 提交于 2019-12-05 01:12:56
当我们想给我们的应用给一个设置页面的时候,我第一反应就想到了PreferenceActivity,但我们小组的头说系统默认的PreferenceActivity不符合客户的需求,我不甘心,就开始自己在网上寻找资料,订制一个想要的PreferenceActivity页面。 功夫不负有心人,经过了2天的奋斗终于出了成果,也很感谢网上那些分享成果的哥们,他们让我受益良多。 下面是我自己订制的PreferenceActivity的效果: 外面整个是一个PreferenceScreen,里面包裹了5个Preference,前两个是继承了CheckBoxPreference,第三个是继承了ListPreference,最后两个是继承了普通的Preference,不过为它们专门添加了点击事件。 背景是白色的,代码如下: this.getListView().setBackgroundResource(R.drawable.preference_background); 因为PreferenceActivity其实是继承了ListActivity的,而它加载的整个View也是基于ListActivity中那个ListView的,所以直接设置就可以了,不过好像使用setBackgroundColor()这个方法没有效果,我也没搞明白,有大神帮忙解答一下。 我在下面是我在res