小编mor*_*ium的帖子

android - 如何在Android 3.0中为PreferenceActivity设置自定义布局?

我正在使用minSdkVersion ="11"开发应用程序,这是适用于平板电脑和Android 4.0及更新版本的应用程序.我已经仔细审查了这个话题,但是没有找到太多.

要为以前版本的Android SDK实现自定义布局,我们只需要使用ListView创建布局(比如preference.xml),其id等于android.R.id.list并使用setContentView方法.

preference.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" > 
    <ListView android:id="@android:id/list"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent" /> 
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

在Android 3.0中,事情发生了变化,使用片段实现了Preferences.这就是我的preference_headers.xml文件的样子:

<preference-headers
        xmlns:android="http://schemas.android.com/apk/res/android">

    <header android:fragment="com.example.MyPreferenceActivity$GeneralSettingsFragment" 
            android:title="General"
            android:summary="Common settings." />
    <header  
            android:title="Example.com" >
        <intent android:action="android.intent.action.VIEW"
                android:data="http://www.example.com" />
    </header> 

</preference-headers>
Run Code Online (Sandbox Code Playgroud)

MyPreferenceActivity.java:

public class MyPreferenceActivity extends PreferenceActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.preference);
        // Add a button to the header list.
        if (hasHeaders()) {
            Button button = new Button(this); 
            button.setText("Log out");
            setListFooter(button);

        }

    }


    /**
     * Populate the …
Run Code Online (Sandbox Code Playgroud)

android preferenceactivity android-3.0-honeycomb

16
推荐指数
2
解决办法
1万
查看次数

在Android 3.0+中使用Android.app.Fragment和ViewPager

我用android开发应用程序:minSdkVersion ="11".据我所知,ViewPager是在兼容性库中实现的.我已成功通过添加android-support-v4.jar库使其在我的应用程序中工作,但现在我不得不使用

android.support.v4.app.FragmentActivity

因为我需要用于FragmentPagerAdapter的getSupportFragmentManager(),而不是新的android.app.Activity的getFragmentManager().

我也需要使用

android.support.v4.app.Fragment

代替

android.app.Fragment

它虽然有效,但我绝对不喜欢这种方法.它破坏了应用程序的设计,我不想在我的API Level 11项目中拥有兼容性库.

还有其他更原生的方法可以在Honeycomb +应用程序中使用ViewPager吗?

android android-3.0-honeycomb android-viewpager

7
推荐指数
2
解决办法
4272
查看次数