如何实现首选项?

时间:2018-09-13 04:34:14

标签: java android xml android-studio

我正在尝试使用“首选项”屏幕。为此,我有一个扩展PreferenceFragmentCompat的类。最初我想使用PreferenceFragment,但已过时,因此知道我必须使用PreferenceFragmentCompat。知道要使用它,我必须在build.gradle文件的依赖项中添加一个实现。这是我当前的依赖项:

    dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support:preference-v7:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'org.apache.directory.studio:org.apache.commons.io:2.4'
}

现在这是我的片段的代码:

    public class ConfigFragment extends PreferenceFragmentCompat {

public static ConfigFragment newInstance() {

    Bundle args = new Bundle();

    ConfigFragment fragment = new ConfigFragment();
    fragment.setArguments(args);
    return fragment;
}


  @Override
  public void onCreatePreferences(Bundle bundle, String s) {
    addPreferencesFromResource(R.xml.preferences);
 }
}

我当前在Logcat中收到此错误:

  

安装APK时出错

在调试中,我收到此错误:

  

09-13 00:31:45.137 1613-5102 /? E / AudioFlinger:createRecordTrack_l()initCheck失败-12;没有控制块?   09-13 00:31:45.140 2505-16972 /? E / IAudioFlinger:createRecord返回错误-12   09-13 00:31:45.140 2505-16972 /? E / AudioRecord:AudioFlinger无法创建记录轨道,状态:-12   09-13 00:31:45.140 2505-16972 /? E / AudioRecord-JNI:创建AudioRecord实例时出错:初始化检查失败,状态为-12。   09-13 00:31:45.141 2505-16972 /? E / android.media.AudioRecord:初始化本机AudioRecord对象时出现错误代码-20。

     

起因:com.google.android.apps.gsa.shared.exception.GsaIOException:错误代码:393238 |缓冲区溢出,没有可用空间。

有趣的是,我没有使用AudioRecord,但仍然收到此错误。添加首选项实现后,我将显示错误。如何解决此问题或正确实现PreferenceFragmentCompat?

0 个答案:

没有答案
相关问题