gpt4 book ai didi

Android:如何制作自定义 PreferenceScreen?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:01:37 39 4
gpt4 key购买 nike

我正在尝试创建一个 PreferenceScreen,但我希望 Activity 设计与整个项目一样。

如何创建自定义 PreferenceScreen 设计?

最佳答案

是的,这是可行的。为布局道歉,我的粘贴似乎从来没有保持正确的格式,但内容有效......

首选项.java

  import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.View;
import android.widget.Button;

public class Preferences extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.preference_holder);
addPreferencesFromResource(R.layout.preferences);

Button backButton = (Button) findViewById(R.id.backPrefBurron);
backButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(getBaseContext(),
BTFirstTab.class);
startActivity(myIntent);
}
});

}
}

然后是首选项 holder.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout android:orientation="horizontal"
android:background="@color/bto_dark_green" android:layout_width="fill_parent"
android:gravity="center_vertical" android:layout_height="wrap_content"
android:paddingTop="4dip">
<Button android:id="@+id/backPrefBurron" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Home" />

<TextView android:id="@+id/backText" android:textSize="14dip"
android:paddingLeft="5dip" android:textColor="@color/white"
android:textStyle="bold" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1.0"
android:text="Preferences: Home will update all areas of the app" />
</LinearLayout>
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>

然后是 preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/bto_light_green">

<EditTextPreference android:title="Your BTO UserName"
android:key="username" android:summary="Please provide your username"> </EditTextPreference>
<EditTextPreference android:title="Your BTO Password"
android:password="true" android:key="password" android:summary="Please provide your password (case sensitive)"></EditTextPreference>
<ListPreference android:title="Species order"
android:summary="This preference selects the species order for some viewing sightings activities"
android:key="speciesorder" android:defaultValue="date_order" android:entries="@array/listArray"
android:entryValues="@array/listValues"></ListPreference>
</PreferenceScreen>

这样我就有了一个在其他页面中使用的通用标题。

关于Android:如何制作自定义 PreferenceScreen?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8922977/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com