我将 SherlockPreferenceActivity 用于 xml 文件中的首选项 Activity 。代码如下:
public class Setting extends SherlockPreferenceActivity
{
protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
addPreferencesFromResource(R.xml.setting);
}
一切正常,但我需要左右边距为 0dip(下图)
我试图在 ABS 源代码中找到但未能自定义它。有人做过吗?
更新:我上传了更多细节图片
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>
最佳答案
这样使用:
在 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/