开发中遇到的问题, Mark下
1.修改PreferenceFragment的ScrollBar样式
PreferenceFragment并没有提供相关接口,因此想要修改的话,需要重新写layout
package com.android.abc;
import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.example.my.demo.R;
import java.util.jar.Attributes;
public class CustomPreferenceFragment extends PreferenceFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.custom_preference_list_fragment, container, false);
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.demo_preference);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container_material"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<FrameLayout
android:id="@android:id/list_container"
android:layout_height="0px"
android:layout_weight="1"
android:layout_width="match_parent" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:divider="@null"
android:dividerHeight="0dp"
android:drawSelectorOnTop="false"
android:fadeScrollbars="false"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarFadeDuration="0"
android:scrollbarSize="1dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"
android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"
android:scrollbars="vertical" />
</FrameLayout>
</LinearLayout>
scrollbar_vertical_thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<size android:width="1dp" android:height="60dp" />
<corners android:radius="2px" />
<solid android:width="2px" android:color="#FF3098FA" />
</shape>
</item>
</selector>
scrollbar_vertical_track.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="6px" />
<solid android:width="6px" android:color="#FF2A3039" />
</shape>
</item>
</selector>
效果如下:
未完待续...
转载请注明出处o(∩_∩)o