I get the parent layout of preferenceScreen
on lower than Android N is the following code :
final Dialog dialog = preferenceScreen.getDialog();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
Log.d("TAG",dialog.findViewById(android.R.id.list).getParent().getClass()+"");
LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent();
} else {
ViewGroup root = (ViewGroup) dialog.findViewById(android.R.id.content);
}
Here is the layout of PreferenceScreen in Android source code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="@android:color/transparent"
android:layout_removeBorders="true">
<ListView android:id="@android:id/list"
style="?attr/preferenceFragmentListStyle"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:paddingTop="0dip"
android:paddingBottom="@dimen/preference_fragment_padding_bottom"
android:scrollbarStyle="@integer/preference_fragment_scrollbarStyle"
android:clipToPadding="false"
android:drawSelectorOnTop="false"
android:cacheColorHint="@android:color/transparent"
android:scrollbarAlwaysDrawVerticalTrack="true" />
......other widget......
</LinearLayout>
It works well on lower than Android N,But when I run my app in Android N, show error that the parent of ListView that id is android.R.id.list is FrameLayout not LinearLayout. The Android source code explained that it is LinearLayout not FrameLayout,but why error?