问题描述
我突然停止了我的应用程序的开发,因为我意识到这个库不支持 PreferenceFragments.android 新手开发者是否可以使用其他替代方法来克服这个障碍?
I've come to a sudden halt in the development of my app as I realized that PreferenceFragments weren't supported in this library. Are there any alternatives that a rookie android developer can use to overcome this obstacle ?
这是我现在的主窗口
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0"/>
<FrameLayout
android:id="@+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
/>
</TabHost>
</LinearLayout>
对于我的 TabActivity,我使用的是我在网上找到的东西.这是一个片段:
For my TabActivity I'm using something I found online. Here's a snippet:
public class TabControlActivity extends FragmentActivity implements TabHost.OnTabChangeListener
{
public static final int INSERT_ID = Menu.FIRST;
public static TabControlActivity thisCtx;
private TabHost mTabHost;
private HashMap mapTabInfo = new HashMap();
private TabInfo mLastTab = null;
private class TabInfo {
private String tag;
private Class clss;
private Bundle args;
private Fragment fragment;
TabInfo(String tag, Class clazz, Bundle args) {
this.tag = tag;
this.clss = clazz;
this.args = args;
}
}
class TabFactory implements TabContentFactory
{
private final Context mContext;
/**
* @param context
*/
public TabFactory(Context context) {
mContext = context;
}
/** (non-Javadoc)
* @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String)
*/
public View createTabContent(String tag) {
View v = new View(mContext);
v.setMinimumWidth(0);
v.setMinimumHeight(0);
return v;
}
}
...*snip*...
是否可以使用 android-support-v4 兼容性库来实现类似于首选项片段(或首选项活动)的内容?
Is there any to implement something that resembles a preferencefragment(or preferenceActivity) using the android-support-v4 compatibility library ?
推荐答案
UPDATE - 6/11/2015
Support-v7 库现在包括 PreferenceFragmentCompat
.所以最好使用它.
将以下项目作为库项目添加到您的应用程序中.
Add the following project as a library project to your application.
https://github.com/kolavar/android-support-v4-preferencefragment
您可以保留所有内容,包括您的片段交易.导入 PreferenceFragment
类时,请确保正确的导入标头是 user.
You can keep everything including your fragment transaction as it is. When importing the PreferenceFragment
class, make sure the correct import header is user.
import android.support.v4.preference.PreferenceFragment;
代替
import android.preference.PreferenceFragment;
这篇关于使用 android-support-v4 替代 PreferenceFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!