17
I am developing app with minSdkVersion="11", that is app for tablets and Android 4.0 and newer. I have scrutinized internet on this topic, but have not found much.
To implement custom layout for previous versions of Android SDK we just have to create layout (say preference.xml) with ListView and its id equals to android.R.id.list and use setContentView method.
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>
In Android 3.0 things have changed and Preferences are implemented with use of fragments. That is how my preference_headers.xml file looks like:
<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>
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(butt