如何在Activity中使用PreferenceFragment?

时间:2016-05-26 03:17:46

标签: android eclipse android-preferences preferencefragment

我遇到问题,我创建了偏好设置并添加了导航栏活动,但导航栏活动是堆栈透明的,如果我点击它,则没有任何反应。

我一直坚持如何在PreferenceFragment中创建导航栏,请帮助我。

我已经搜索了相同的最佳做法。

以下是我的代码类ScheduleSetting

public class ScheduleSetting extends AppControllerFragment {

    /***************** LEFT MENU *****************/
    public SlidingMenu menu;
    LinearLayout LeftMenu;
    LinearLayout logoLyt;
    /***************** LEFT MENU *****************/

    /********************** INTENT PARAMS **********************/
    Bundle b;
    Intent ThisIntent;
    /********************** INTENT PARAMS **********************/

    /*************************************** IMAGE LOADER ***********************************/
    public static DisplayImageOptions options, options2;
    public static ImageLoaderConfiguration config;
    public static ImageLoader imageLoader = ImageLoader.getInstance();
    /*************************************** IMAGE LOADER ***********************************/

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        /********************** SET VIEW **********************/
        getFragmentManager().beginTransaction().add(android.R.id.content,
                    new test()).commit();

        setContentView(R.layout.schedule_setting);
        beforeFilter(ScheduleSetting.this);
        /********************** SET VIEW **********************/

        /********************** INTENT PARAMS **********************/
        ThisIntent = activity.getIntent();
        b = ThisIntent.getExtras();
        if (b == null)
            b = new Bundle();
        /********************** INTENT PARAMS **********************/

        /***************** LEFT MENU *****************/
        logoLyt         =   (LinearLayout) activity.findViewById(R.id.logoLyt);
        LeftMenu        =   (LinearLayout) activity.findViewById(R.id.LeftMenu);
        DefineMenu();
        /***************** LEFT MENU *****************/
}

这是扩展PreferenceFragment的类测试:

    public static class test extends PreferenceFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       addPreferencesFromResource(R.xml.settings);

       }
}

这是我的用户界面静态​​堆栈菜单导航栏和首选项:

Image Of Setting Activity

这是我的schedule_setting.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/parentLayout"
    style="?attr/page_background"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:descendantFocusability="beforeDescendants"
    android:focusable="false"
    android:focusableInTouchMode="true"
    android:gravity="top|left"
    android:orientation="vertical" >

    <!-- HEADERS -->
    <LinearLayout
        android:id="@+id/headerLyt"
        style="?attr/header"
        android:layout_width="match_parent"
        android:layout_height="@dimen/header_height"
        android:gravity="center_vertical|left"
        android:orientation="horizontal" >

        <LinearLayout
            android:id="@+id/LeftMenu"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:clickable="true"
            android:gravity="left|center_vertical" >

            <ImageView
                android:layout_width="18dp"
                android:layout_height="13dp"
                android:layout_marginLeft="5dp"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                android:src="@drawable/left_menu_icon_2" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/logoLyt"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:clickable="true"
            android:gravity="left|center_vertical"
            android:visibility="visible" >
            <TextView
                android:layout_marginLeft="10dp"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="left|center_vertical"
                android:textColor="@color/white"
                android:textSize="20sp"
                android:text="SCHEDULE SETTING"
                android:tag="EconomicaRegular"
                />
        </LinearLayout>
    </LinearLayout>
    <!-- HEADERS -->

    <!-- CONTENT -->
    <com.handmark.pulltorefresh.library.PullToRefreshListView
        xmlns:ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@android:color/transparent"
        android:cacheColorHint="@android:color/transparent"
        android:divider="@android:color/transparent"
        android:dividerHeight="10dp"
        android:drawSelectorOnTop="false"
        android:listSelector="@android:color/transparent"
        android:overScrollMode="never"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:scrollbars="none"
        ptr:ptrAnimationStyle="flip"
        ptr:ptrHeaderTextColor="@color/black"
        ptr:ptrMode="pullFromStart"
        ptr:ptrRefreshableViewBackground="@android:color/transparent" />
    <!-- CONTENT -->

</LinearLayout>

这是我的settings.xml(对于首选项设置):

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

  <PreferenceCategory
    android:title="@string/title_domicile" >
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefJakartaPusat"
        android:summary="@string/summary_jakarta_pusat"
        android:title="@string/title_jakarta_pusat" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefJakartaBarat"
        android:summary="@string/summary_jakarta_barat"
        android:title="@string/title_jakarta_barat" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefJakartaUtara"
        android:summary="@string/summary_jakarta_utara"
        android:title="@string/title_jakarta_utara" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefJakartaSelatan"
        android:summary="@string/summary_jakarta_selatan"
        android:title="@string/title_jakarta_selatan" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefJakartaTimur"
        android:summary="@string/summary_jakarta_timur"
        android:title="@string/title_jakarta_timur" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefBekasiUtara"
        android:summary="@string/summary_bekasi_utara"
        android:title="@string/title_bekasi_utara" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefBekasiTimur"
        android:summary="@string/summary_bekasi_timur"
        android:title="@string/title_bekasi_timur" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefBogorBarat"
        android:summary="@string/summary_bogor_barat"
        android:title="@string/title_bogor_barat" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefBogorSelatan"
        android:summary="@string/summary_bogor_selatan"
        android:title="@string/title_bogor_selatan" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefBogorTengah"
        android:summary="@string/summary_bogor_tengah"
        android:title="@string/title_bogor_tengah" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefBogorTimur"
        android:summary="@string/summary_bogor_timur"
        android:title="@string/title_bogor_timur" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefBogorUtara"
        android:summary="@string/summary_bogor_utara"
        android:title="@string/title_bogor_utara" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefKotaDepok"
        android:summary="@string/summary_kota_depok"
        android:title="@string/title_kota_depok" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefTangerang"
        android:summary="@string/summary_tangerang"
        android:title="@string/title_tangerang" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefTangerangSelatan"
        android:summary="@string/summary_tangerang_selatan"
        android:title="@string/title_tangerang_selatan" />
  </PreferenceCategory>

 <PreferenceCategory
   android:title="@string/title_days" >
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefSenin"
        android:summary="@string/summary_senin"
        android:title="@string/title_senin" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefSelasa"
        android:summary="@string/summary_selasa"
        android:title="@string/title_selasa" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefRabu"
        android:summary="@string/summary_rabu"
        android:title="@string/title_rabu" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefSenin"
        android:summary="@string/summary_kamis"
        android:title="@string/title_kamis" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefSenin"
        android:summary="@string/summary_jumat"
        android:title="@string/title_jumat" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefSenin"
        android:summary="@string/summary_sabtu"
        android:title="@string/title_sabtu" />
      <CheckBoxPreference
        android:defaultValue="false"
        android:key="prefMinggu"
        android:summary="@string/summary_minggu"
        android:title="@string/title_minggu" />
 </PreferenceCategory>

 <PreferenceCategory
   android:title="@string/title_times" >
  <ListPreference
     android:entries="@array/OptionStartTime"
     android:entryValues="@array/ValueStartTime"
     android:key="prefStartTime"
     android:summary="@string/summary_start"
     android:title="@string/title_start" />
   <ListPreference
     android:entries="@array/OptionEndTime"
     android:entryValues="@array/ValueEndTime"
     android:key="prefEndTime"
     android:summary="@string/summary_end"
     android:title="@string/title_end" />
 </PreferenceCategory>

</PreferenceScreen>

1 个答案:

答案 0 :(得分:0)

我通过以下方法解决了该问题:import { global.RoutesOffersPage } from './globalConstant.js' import { global.RoutesActionPage } from './globalConstant.js' var templateOffersPage = ejs.compile(fs.readFileSync(__dirname + '/offersPageTemplate.ejs', 'utf-8')) var paths = global.RoutesOffersPage.routes.map(r => r.url); var paths2 = global.RoutesActionPage.routes.map(r => r.url); //do stuff

查看我的代码:

SyntaxError: Unexpected token import

对于PreferenceFragment:

setContentView(R.layout.schedule_setting);

See the result, navbar is clickable