我为我的应用程序设置了一个设置菜单,但是想知道如果在菜单中单击首选项时我将如何开始活动?我希望用户能够点击菜单栏上的"更改密码"并启动另一个活动,这样他们就可以输入密码,输入新密码,并确认新密码,这样就可以更改共享密码文件.如果还有其他更简单的方法,我会非常感谢输入.谢谢
我正在尝试创建我自己的ImagePreference,我将在我的应用首选项中使用它,以便选择用户选择代表自己的图片.
我不太确定我在做什么,但基本上我正在模仿其他一些偏好课程.到目前为止,我只是遇到了这种方法的问题:
public class ImagePreference extends Preference {
...
void sendAccessibilityEvent(View view) {
// Since the view is still not attached we create, populate,
// and send the event directly since we do not know when it
// will be attached and posting commands is not as clean.
AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getContext());
if (mSendClickAccessibilityEvent && accessibilityManager.isEnabled()) {
AccessibilityEvent event = AccessibilityEvent.obtain();
event.setEventType(AccessibilityEvent.TYPE_VIEW_CLICKED);
view.onInitializeAccessibilityEvent(event);
view.dispatchPopulateAccessibilityEvent(event);
accessibilityManager.sendAccessibilityEvent(event);
}
mSendClickAccessibilityEvent = false;
}
Run Code Online (Sandbox Code Playgroud)
我刚刚从TwoStatePreference类复制了这段代码.我甚至不确定我是否需要这个方法,但编译器抱怨说AccessibilityManager类不包含getInstance方法.
我认为这可能是导入的问题,但我导入了与TwoStatePreference相同的类,即:
import android.view.accessibility.AccessibilityManager;
Run Code Online (Sandbox Code Playgroud)
我已经因为这个问题已经失去了几个小时.知道编译器为什么抱怨?
谢谢!
任何人都可以向我建议一种在更改CheckboxPreference或SwitchPrerence(例如)时执行AlertDialog确认更改的方法。如果我要取消选中首选项,则AlertDialog应该警告它们,例如“您确定要取消选中吗?” 加上对话框应该可自定义,因为我要使用自己的布局。我不希望对话框带有默认的Bluestrip标头。
SwitchPreference pref = (SwitchPreference) findPreference("prefkey_use_passcode");
pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference arg0, Object arg1) {
DialogPreference dialog = new DialogPreference(getParent());
return false;
}
});
Run Code Online (Sandbox Code Playgroud) 我需要一个数据库,我可以随时存储数据并获取数据.这是可能的android.preference包.我不想使用sqlite数据库
问候
我正在扩展PreferenceActivity我的设置屏幕。在这个偏好活动中,我有几个偏好,其中一个是定制的。问题如下:
在此自定义首选项(从 扩展ListPreference)中,我希望能够设置默认值,因此我覆盖了该setDefaultValue()方法。在这种方法中,我进行了一些解析,因此它将采用正确的值。当我试图用getValue()函数读取这个值时,它只返回null.
所以我想,当我把一些硬编码的值放在那里时会发生什么(你知道,也许我做错了什么,这不是第一次)。嗯,我还是null回来了。
任何想法我做错了什么?
编辑:
在 xml 文件中设置 defaultValue 并不是一个真正的选项,因为在我检索它们之前这些值是未知的。
我做了一个解决方法:
这样我在收集数据时设置了默认首选项
android preference preferenceactivity android-preferences listpreference
我最近偶然发现了一个问题.
我正在使用这样的嵌套PreferenceScreen:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceScreen
android:key="pref_name"
android:title="@string/pref_title" >
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
当我的屏幕将焦点放在嵌套首选项屏幕上并且我更改屏幕方向时,嵌套的首选项屏幕将关闭.
我也试过包括:
android:configChanges="orientation|keyboardHidden"
Run Code Online (Sandbox Code Playgroud)
在AndroidManifest.xml中,但没有奏效.
有人有解决方案吗?
编辑可能的解决方案:
我确实找到了解决方案.我以为是这条线:
android:configChanges="keyboardHidden|orientation|screenSize"
Run Code Online (Sandbox Code Playgroud) 我通过使用这个例子添加了一个偏好:http: //git.eclipse.org/c/platform/eclipse.platform.ui.git/plain/examples/org.eclipse.ui.examples.readmetool/Eclipse%20UI%20Examples %20Readme%20Tool /组织/蚀/ UI /示例/ readmetool /
有关实际参考,请参阅此页面:http: //git.eclipse.org/c/platform/eclipse.platform.ui.git/plain/examples/org.eclipse.ui.examples.readmetool/Eclipse%20UI%20Examples %20Readme%20Tool/org/eclipse/ui/examples/readmetool/ReadmePreferencePage.java)
我只添加了一个复选框来测试它,当我搜索首选项中的复选框中的任何单词时,我看不到我的视图即将出现,但如果我输入当前Eclipse有的东西,那么它出现(即我输入背景,我可以看到)在常规选项卡住并且是粗体).
我想我不知何故需要添加搜索关键字来指向当前页面(或其他东西).但我找不到如何添加,或导致此问题的原因.
那么如何在" 首选项"窗口中为我创建的首选项执行搜索?
请点击查看图片 http://i1094.photobucket.com/albums/i455/tdounnyy/device.png
在此PreferenceActivity的底部,"选择铃声"右侧有一个图标/按钮.
并且"振动"没有.
此振动偏好是一个客户偏好扩展偏好.
我想在Vibrate行中放置相同的Icon.一种方法是扩展ListPreference或RingtonePreference来欺骗操作系统.
我不喜欢这样,想知道是否有更好的解决方案.^ _ ^
preferences.xml感谢@Femi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific …Run Code Online (Sandbox Code Playgroud) 我已经看了一遍解决我的问题,似乎无法弄明白.我敢肯定它可能是1或2条简单的线条,希望有人可以引导我朝着正确的方向前进.
在我的应用中,用户可以单击将打开图库的按钮.一旦他们选择了图像,它就会在我的应用程序中的ImageView中显示该图像.那部分工作得非常好.最初,我只是从画廊返回一个uri,我会直接显示:
imageView1.setImageURI(myUri);
Run Code Online (Sandbox Code Playgroud)
好吧,显然我现在遇到了可怕的"Out Of Memory"错误,如果用户连续多次重新加载该页面,那么我必须清理我的代码以缩小图像.我通过实现一个位图类来实现这一点,该类将图像转换为位图并为我缩小位图.现在,我的ImageView显示代码如下所示:
imageView1.setImageBitmap(bitmap1);
Run Code Online (Sandbox Code Playgroud)
那部分工作正常.这是问题:
我将uri路径转换为字符串,然后将其保存在SharedPreference中.这样当用户退出应用程序并稍后返回时,它们自动显示的图像就会显示出来.我像这样转换uri:
...
selectedImageUri = data.getData();
String selectedImagePath;
selectedImagePath = getPath(selectedImageUri);
...
Run Code Online (Sandbox Code Playgroud)
检索SharedPreference字符串的旧方法,将其转换为uri,然后显示它工作正常.(当然,除了Out Of Memory错误)它看起来像这样:
Uri myUri = Uri.parse(selectedImagePath);
imageView1 = setImageURI(myUri);
Run Code Online (Sandbox Code Playgroud)
"selectedImagePath"显然是我从SharedPreference中检索到的String.再次,这工作正常,但如果重新加载太多次将抛出错误.
现在不工作的部分是当我尝试实现新的Bitmap转换时,我可以缩放位图而不会出现内存错误.这是代码:
Uri myUri = Uri.parse(selectedImagePath)
Bitmap bitmap = getThumbnail(myUri);
imageView1.setImageBitmap(bitmap);
Run Code Online (Sandbox Code Playgroud)
这没什么.原始图像选择显示图像正常但当我返回到此屏幕并尝试从SharedPreference解析字符串然后将其转换为位图时,什么都没有显示."getThumbnail"方法的代码直接来自THIS POST --->
这是第三个答案.
有人有主意吗?对不起,超长的帖子,但我宁愿解释我的问题,而不是提供足够的信息.对不起,如果在其他地方得到了回答.我一直在寻找其他问题几个小时,并没有找到解决我的问题的任何东西.
谢谢.
我不知道这个错误。我从Google开发人员控制台获得了这些消息。z3,htc m8,m9等某些设备无法执行我的应用。有人可以给我一些有关该错误的提示吗?
堆栈跟踪 :
java.lang.RuntimeException: Unable to start activity ComponentInfo{package name/package name.SettingsActivity}: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2499)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2563)
at android.app.ActivityThread.access$800(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:209)
at android.app.ActivityThread.main(ActivityThread.java:5900)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1005)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:800)
Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class com.android.internal.widget.ActionBarContainer
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3659)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3755)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:403)
at android.app.Activity.setContentView(Activity.java:2174)
at android.preference.PreferenceActivity.onCreate(PreferenceActivity.java:553)
at …Run Code Online (Sandbox Code Playgroud)