android - 自定义操作栏 Sherlock PreferenceActivity ListView

标签 android listview actionbarsherlock preferenceactivity

我将 SherlockPreferenceActivity 用于 xml 文件中的首选项 Activity 。代码如下:

public class Setting extends SherlockPreferenceActivity
{
protected void onCreate(Bundle paramBundle)
{
  super.onCreate(paramBundle);
  addPreferencesFromResource(R.xml.setting);
}

一切正常,但我需要左右边距为 0dip(下图) enter image description here

我试图在 ABS 源代码中找到但未能自定义它。有人做过吗?

更新:我上传了更多细节图片 enter image description here

setting.xml内容:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
    <PreferenceCategory android:title="@string/system_setting" >
        <CheckBoxPreference
            android:defaultValue="true"
            android:key="mode_on_off"
            android:summaryOff="Sub Setting 1"
            android:summaryOn="Sub Setting 1 On"
            android:title="Setting 1" />
        <CheckBoxPreference
            android:defaultValue="true"
            android:key="filter_on_off"
            android:summaryOff="Sub Setting 2"
            android:summaryOn="Sub Setting 2 On"
            android:title="Setting 2" />
        <CheckBoxPreference
            android:defaultValue="false"
            android:key="screen"
            android:summaryOff="Sub Setting 3"
            android:summaryOn="Sub Setting 3 on"
            android:title="Setting 2" />

    </PreferenceCategory>
</PreferenceScreen>

最佳答案

这样使用:

enter image description here

在 Activity 中:

import android.os.Bundle;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockPreferenceActivity;

public class MainActivity extends SherlockPreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.custom_infowindow);
        final ActionBar actionBar = getSupportActionBar();
        actionBar.setCustomView(R.layout.custom_infowindow);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayUseLogoEnabled(false);
        actionBar.setDisplayShowHomeEnabled(false);

        addPreferencesFromResource(R.xml.test);
    }

}

自定义信息窗口.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Right Now Event"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#FF0000" />

    <View
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:background="@color/_blue" />

</LinearLayout>

关于android - 自定义操作栏 Sherlock PreferenceActivity ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16461518/

相关文章:

android - 将 Android Studio 更新到 4.0 后,Android View Binding 库出错

java - EditText.setFocusable(false);不能设置为真。 :/

java - Android 多种实现 - 仅触发了一半事件

java - 如何在片段 'for loop' 中停止 'Android studio"?

android - 如何在 Android 2.3.3 的 ListView 中突出显示选定的行。 (HoloeveryWhere + ABS)

android - ACRA LogCat 参数未按预期工作

flutter - flutter :listview空白分隔线

android - List<Class> 上的空指针异常

android - 当焦点从 EditText 更改为 Button 时 ActionBarSherlock 操作栏消失

带有搜索 View 的 Android 操作栏