Skip to content

Commit

Permalink
Merge pull request #4 from davcpas1234/nested-redo
Browse files Browse the repository at this point in the history
Nested Screen Fix [release] 1.0.2
  • Loading branch information
davcpas1234 committed Feb 15, 2016
2 parents a81fe70 + 4466d36 commit 4c4d238
Showing 1 changed file with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,35 +213,44 @@ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preferen
public void setUpNestedScreen(PreferenceScreen preferenceScreen) {
final Dialog dialog = preferenceScreen.getDialog();

AppBarLayout bar;
AppBarLayout appBar;

View listRoot = dialog.findViewById(android.R.id.list);
ViewGroup mRootView = (ViewGroup) dialog.findViewById(android.R.id.content);


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent();
bar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_settings, root, false);
root.addView(bar, 0);
appBar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_settings, root, false);
root.addView(appBar, 0);
} else {
ViewGroup root = (ViewGroup) dialog.findViewById(android.R.id.content);
ListView content = (ListView) root.getChildAt(0);
root.removeAllViews();
bar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_settings, root, false);
ListView content = (ListView) mRootView.getChildAt(0);
mRootView.removeAllViews();

int height;
TypedValue tv = new TypedValue();
if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
}else{
height = bar.getHeight();
}
LinearLayout LL = new LinearLayout(this);
LL.setOrientation(LinearLayout.VERTICAL);

content.setPadding(0, height, 0, 0);
ViewGroup.LayoutParams LLParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
LL.setLayoutParams(LLParams);

root.addView(content);
root.addView(bar);
appBar = (AppBarLayout) LayoutInflater.from(this).inflate(R.layout.toolbar_settings, mRootView, false);

LL.addView(appBar);
LL.addView(content);

mRootView.addView(LL);
}

Toolbar Tbar = (Toolbar) bar.getChildAt(0);
if(listRoot != null){
listRoot.setPadding(0, listRoot.getPaddingTop(), 0, listRoot.getPaddingBottom());
}

Toolbar Tbar = (Toolbar) appBar.getChildAt(0);

Tbar.setTitle(preferenceScreen.getTitle());

Tbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
Expand Down

0 comments on commit 4c4d238

Please sign in to comment.