我的Google-Fu今天失败了这个Android新手.
有没有人知道如何从PreferenceScreen启动一个意图?
就像是:
    <PreferenceScreen
        android:key="preference_some_new_layout"
        android:title="@string/pref_some_title">
            <intent android:action="????" /> 
    </PreferenceScreen>
我想展示一个自定义的LinearLayout,它允许我设置一些半复杂的首选项.
最好的方法是什么?
谢谢,wTs
我的应用程序有一个ListPreference,其条目来自网络API.在我的PreferenceActivity的onCreate()中,我生成了一个后台线程,它进行API调用,然后在一两秒后填充ListPreference的条目.
如果用户在下载选项之前单击首选项屏幕上的ListPreference按钮,我想阻止显示首选项对话框,而是通知用户仍在加载选项列表.
我怀疑正确的方法是覆盖OnPreferenceClickListener,如下所示:
ListPreference dpref = (ListPreference) findPreference("debug");
String[] s = {"one", "two", "three"};
dpref.setEntries(s);
dpref.setEntryValues(s);
dpref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
    @Override
    public boolean onPreferenceClick(Preference preference) {
        Toast.makeText(this, "hi there", Toast.LENGTH_SHORT).show();
        return true;
    }
});
将显示toast,但也会显示ListPreference选择器对话框.该OnPreferenceClickListener文件说,onPreferenceClick应该返回true如果点击被处理,但返回false具有相同的效果.
如何阻止首选项对话框显示?
是否有更好的方法来处理在查看之前必须下载选项的首选项?
嗨我想在prefrencescreen中添加一个按钮,我成功地在prefrence中添加了一个按钮,但我无法获得onClick事件.我已将我的代码附加了一张prefence屏幕
Setting.xml的
<PreferenceCategory android:title="Application Details">
    <Preference android:key="type" 
                android:title="Type"
                android:summary="" />
</PreferenceCategory>
<PreferenceCategory android:title="Notification Settings">
    <ListPreference android:key="sendNotificationType"
                    android:title="Status Notification For"
                    android:dialogTitle="Status Notification For" />
</PreferenceCategory>
settingdetail.xml
<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_alignRight="@+id/textView2"
    android:layout_marginLeft="15dp"
    android:text="Type"
    android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:layout_marginLeft="15dp"
    android:layout_toLeftOf="@+id/setFromTimeBtn"
    android:text="Summary"
    android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
    android:id="@+id/buyItNowBtn"
    android:layout_width="80dp"
    android:layout_height="30dp"
    android:layout_alignParentRight="true"
    android:layout_marginRight="15dp"
    android:layout_centerVertical="true"
    android:background="@drawable/button"
    android:text="@string/buyItNowBtnTxt"
    android:textColor="@color/white" />
和prefenceActivity类的onCreate方法
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.layout.setting);
    setContentView(R.layout.settingview);
    Preference typePref = (Preference) findPreference("type");
    typePref.setLayoutResource(R.layout.settingdetail);
typePref.setSelectable(true);
    Button btn = (Button) findViewById(R.id.buyItNowBtn);
    btn.setOnClickListener(new …我已经阅读了这个线程FATAL EXCEPTION主要Android应用程序,它是非常有帮助的.
是的,这很好用
<string formatted="false">some text and % in the text</string>
所以如果有人使用xml格式化的="false"就是解决方案.
但我的代码有问题
getPreferenceScreen().findPreference("my_key").setSummary("some text and % in the text"));
这有一个例外,有谁知道如何逃脱%?
因此,当调用String.format()时,%将被视为'%'而不是特殊字符
谢谢
这是我的首选项xml文件:myPreferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory>
    <EditTextPreference android:key="name" android:title="Name" android:inputType="text" android:defaultValue="" />
    <EditTextPreference android:key="email" android:title="Email" android:inputType="textEmailAddress" android:defaultValue="" />
    <EditTextPreference android:key="phone" android:title="Phone Number" android:inputType="phone" android:defaultValue="" />
    <EditTextPreference android:key="zipcode" android:title="Zip Code" android:inputType="number" android:defaultValue="" />
</PreferenceCategory>
</PreferenceScreen>
这是我在AndroidManifest.xml中的首选项活动声明:
<activity
        android:name=".activities.MyPreferencesActivity"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.NoTitleBar" />
而且,这是我之前尝试应用于我的活动的一种风格:
 <activity
     android:name=".activities.MyPreferencesActivity"
     android:screenOrientation="portrait"
     android:theme="@android:style/PreferenceTheme" />
 <style name="PreferenceTheme">
     <item name="android:background">@drawable/background_preferences</item>
     <item name="android:windowNoTitle">true</item>
 </style>
它不起作用.
然后,我尝试通过myCreferencesActivity的onCreate中的java代码来完成它:
 @Override
 protected void onCreate(Bundle savedInstanceState) {
     requestWindowFeature(Window.FEATURE_NO_TITLE);
     super.onCreate(savedInstanceState);
 addPreferencesFromResource(R.xml.myPreferences);
 }
不行.尝试将标题设置为drawable.
 @Override
 protected void onCreate(Bundle savedInstanceState) {
     requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
     super.onCreate(savedInstanceState);
     addPreferencesFromResource(R.xml.preferences_profile);
     getWindow().setFeatureDrawableResource(Window.FEATURE_CUSTOM_TITLE, R.drawable.profile_banner);
 }
不.不行. …
android preferenceactivity android-preferences android-layout
我被困在一个特殊的场景中。用户从应用程序更新时间后,我需要立即更新我的小部件。我确实通过发送Intent Extras数据来尝试广播,但是没有这样做。当前,我的数据存储在AppWidgetProvider中,我需要将此数据发送到服务
公共类CountdownWidget扩展了AppWidgetProvider {// SharedPreferences userDefaults;
// update rate in milliseconds
public static final int UPDATE_RATE = 1800000; // 30 minute
public static String nameOne = "";
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
    for (int appWidgetId : appWidgetIds) {
        setAlarm(context, appWidgetId, -1);
    }
    super.onDeleted(context, appWidgetIds);
}
@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Bundle extras = intent.getExtras();
    nameOne = extras.getString("NAME_ONE");
    Log.e("Name: ", nameOne);
    super.onReceive(context, intent);
}
@Override
public void onUpdate(Context context, AppWidgetManager …我为我的项目添加了一个自定义首选项(下面的代码).我使用自定义widgetLayout将其添加到我的首选项xml中:
<w.PlusOnePreference 
    android:title="Rate App"
    android:key="custom"
    android:widgetLayout="@layout/plusone_pref"/>
首选项布局xml:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.plus.PlusOneButton    
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="@+id/plus_one_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:focusable="false"
plus:size="standard" />
我看到布局和布局中的按钮工作正常.唯一的问题是首选项不可点击.就像隐藏在某些东西背后一样.
有关如何使其可点击的任何想法?
如果我添加常规首选项(没有小部件布局),它可以正常工作.
谢谢.
public class PlusOnePreference extends Preference {
private PlusClient mPlusClient = null; 
public PlusOnePreference(Context context) {
    super(context);
}
public PlusOnePreference(Context context, AttributeSet attrs) {
    super(context, attrs);
}
public PlusOnePreference(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}
public void setPlusClient(PlusClient plusClient) {
    mPlusClient = plusClient;
}
@Override
protected void onBindView(View view) {
    super.onBindView(view);     
    //mPlusOneButton = …我需要在"设置"中实现"重置"选项.单击该设置时,将打开一个简单的对话框,要求确认.
我已经看过了,DialogPreference但似乎无法在任何地方找到一个好的解决方案或教程.有人可以帮帮我吗?我是初学者,想法甚至代码都会非常有帮助,谢谢.
我做了一个自定义DialogPreference,它使用两个NumberPicker小部件,允许用户选择一天中的一小时以及另一个DialogPreference允许用户使用TimePicker小部件选择时间的自定义.
只要对话框未打开并且我旋转屏幕,一切都按预期工作.但是,如果对话框打开并且屏幕旋转,则整个应用程序崩溃.我已经在onSaveInstanceState和onRestoreInstanceState方法中放置了断点,并且已经验证了恢复所需的所有内容都是DialogPreference有序的,onDialogClosed每次都会使用我自定义中的所有其他自定义代码来触发该方法DialogPreference.
我正在建设以下内容:
我正在Verizon Galaxy Nexus上运行Android 4.4.3(KitKat).
这是给出的堆栈跟踪:
java.lang.IndexOutOfBoundsException: setSpan (4 ... 4) ends beyond length 0
  at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1016)
  at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:592)
  at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:588)
  at android.text.Selection.setSelection(Selection.java:76)
  at android.widget.EditText.setSelection(EditText.java:87)
  at android.widget.NumberPicker$SetSelectionCommand.run(NumberPicker.java:2123)
  at android.os.Handler.handleCallback(Handler.java:733)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:136)
  at android.app.ActivityThread.main(ActivityThread.java:5001)
  at java.lang.reflect.Method.invokeNative(Method.java)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
  at dalvik.system.NativeStart.main(NativeStart.java)
android timepicker android-preferences numberpicker android-timepicker
我有一个CheckBoxPreference,我希望默认检查它; 但它不起作用.  
这是我的代码:
在我extends Application班上:
@Override
public void onCreate() {
    super.onCreate();
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPreferences.getBoolean("notify", true);
}
而实际的Pref:
    <CheckBoxPreference
        android:key="notify"
        android:title="Push Notifications"
        android:summary="Receive status bar alerts"/>
    </PreferenceCategory>