• <legend id='nOVIu'><style id='nOVIu'><dir id='nOVIu'><q id='nOVIu'></q></dir></style></legend>
        <bdo id='nOVIu'></bdo><ul id='nOVIu'></ul>
    1. <tfoot id='nOVIu'></tfoot>
      1. <small id='nOVIu'></small><noframes id='nOVIu'>

      2. <i id='nOVIu'><tr id='nOVIu'><dt id='nOVIu'><q id='nOVIu'><span id='nOVIu'><b id='nOVIu'><form id='nOVIu'><ins id='nOVIu'></ins><ul id='nOVIu'></ul><sub id='nOVIu'></sub></form><legend id='nOVIu'></legend><bdo id='nOVIu'><pre id='nOVIu'><center id='nOVIu'></center></pre></bdo></b><th id='nOVIu'></th></span></q></dt></tr></i><div id='nOVIu'><tfoot id='nOVIu'></tfoot><dl id='nOVIu'><fieldset id='nOVIu'></fieldset></dl></div>

        将 LibGDX 与 Android 首选项一起使用

        时间:2023-05-19
      3. <small id='1Kr34'></small><noframes id='1Kr34'>

        <tfoot id='1Kr34'></tfoot>
          <tbody id='1Kr34'></tbody>

            1. <i id='1Kr34'><tr id='1Kr34'><dt id='1Kr34'><q id='1Kr34'><span id='1Kr34'><b id='1Kr34'><form id='1Kr34'><ins id='1Kr34'></ins><ul id='1Kr34'></ul><sub id='1Kr34'></sub></form><legend id='1Kr34'></legend><bdo id='1Kr34'><pre id='1Kr34'><center id='1Kr34'></center></pre></bdo></b><th id='1Kr34'></th></span></q></dt></tr></i><div id='1Kr34'><tfoot id='1Kr34'></tfoot><dl id='1Kr34'><fieldset id='1Kr34'></fieldset></dl></div>
              <legend id='1Kr34'><style id='1Kr34'><dir id='1Kr34'><q id='1Kr34'></q></dir></style></legend>
                <bdo id='1Kr34'></bdo><ul id='1Kr34'></ul>
                • 本文介绍了将 LibGDX 与 Android 首选项一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在尝试将 Andrioid 的首选项系统与 LibGDX 的首选项系统结合使用.他们都使用 SharedPreferences 作为后端,所以我认为他们应该能够一起工作,但是当我尝试在 LibGDX 的首选项中加载数据时,我没有得到任何数据.

                  I'm trying to use Andrioid's preferences system in conjunction with LibGDX's preferences system. They both use SharedPreferences as a backend, so I figure they should be able to work together, but when I try to load the data in LibGDX's preferences, I don't get any data back.

                  我的 Androidpreferences.xml 文件(我知道它很短,稍后会有更多内容:P):

                  My Android preferences.xml file (I know it's short, it'll have much more later :P):

                  <?xml version="1.0" encoding="utf-8"?>
                  <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
                      <EditTextPreference 
                          android:key="framerate"
                          android:title="Set Framerate"
                          android:enabled="true"
                          android:persistent="true"
                          android:defaultValue="25" />
                  </PreferenceScreen>
                  

                  这是我的 PreferenceActivity:

                  Here is my PreferenceActivity:

                  import android.annotation.SuppressLint;
                  import android.annotation.TargetApi;
                  import android.os.Build;
                  import android.os.Bundle;
                  import android.preference.PreferenceActivity;
                  import android.preference.PreferenceFragment;
                  
                  public class WallpaperSettings extends PreferenceActivity {
                  
                      @SuppressLint("NewApi")
                      @SuppressWarnings("deprecation")
                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                          if (Build.VERSION.SDK_INT < 11) {
                              addPreferencesFromResource(R.xml.preferences);
                          } else {
                              getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
                          }
                  
                      }
                  
                      @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                      public static class MyPreferenceFragment extends PreferenceFragment
                      {
                          @Override
                          public void onCreate(final Bundle savedInstanceState)
                          {
                              super.onCreate(savedInstanceState);
                              addPreferencesFromResource(R.xml.preferences);
                          }
                      }
                  }
                  

                  当我从 com.badlogic.gdx.Game 的子类调用它时,我使用

                  When I call it from a subclass of com.badlogic.gdx.Game, I use

                  Preferences pref = Gdx.app.getPreferences("preferences");
                  pref.getInteger("framerate");
                  

                  pref 内的键数为 0.

                  有人知道如何解决这个问题吗?

                  Anyone have a clue as to how this might be fixed?

                  推荐答案

                  感谢http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=6365#p32981 我能够解决这个问题.

                  Thanks to http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=6365#p32981 I was able to solve the problem.

                  请注意,该代码适用于 Android 2.x 和 3.0+.

                  Just a note, the code works for both Android 2.x and 3.0+.

                  import android.annotation.SuppressLint;
                  import android.annotation.TargetApi;
                  import android.os.Build;
                  import android.os.Bundle;
                  import android.preference.PreferenceActivity;
                  import android.preference.PreferenceFragment;
                  
                  public class WallpaperSettings extends PreferenceActivity {
                  
                      @SuppressLint("NewApi")
                      @SuppressWarnings("deprecation")
                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                          if (Build.VERSION.SDK_INT < 11) {
                              addPreferencesFromResource(R.xml.preferences);
                          } else {
                              getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
                          }
                  
                      }
                  
                      @TargetApi(Build.VERSION_CODES.HONEYCOMB)
                      public static class MyPreferenceFragment extends PreferenceFragment
                      {
                          @Override
                          public void onCreate(final Bundle savedInstanceState)
                          {
                              super.onCreate(savedInstanceState);
                              addPreferencesFromResource(R.xml.preferences);
                              getPreferenceManager().setSharedPreferencesName("preferences");
                              getPreferenceManager().setSharedPreferencesMode(0);
                          }
                      }
                  }
                  

                  这篇关于将 LibGDX 与 Android 首选项一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 libgdx 在运行时生成带有文本的纹理 下一篇:libgdx 离开屏幕和屏幕生命周期

                  相关文章

                  最新文章

                  1. <tfoot id='ENQCx'></tfoot>

                    <small id='ENQCx'></small><noframes id='ENQCx'>

                    <legend id='ENQCx'><style id='ENQCx'><dir id='ENQCx'><q id='ENQCx'></q></dir></style></legend>

                        <bdo id='ENQCx'></bdo><ul id='ENQCx'></ul>
                      <i id='ENQCx'><tr id='ENQCx'><dt id='ENQCx'><q id='ENQCx'><span id='ENQCx'><b id='ENQCx'><form id='ENQCx'><ins id='ENQCx'></ins><ul id='ENQCx'></ul><sub id='ENQCx'></sub></form><legend id='ENQCx'></legend><bdo id='ENQCx'><pre id='ENQCx'><center id='ENQCx'></center></pre></bdo></b><th id='ENQCx'></th></span></q></dt></tr></i><div id='ENQCx'><tfoot id='ENQCx'></tfoot><dl id='ENQCx'><fieldset id='ENQCx'></fieldset></dl></div>