Como añadir un menu en la preferenceActivity()
Created
September 30, 2016 10:43
-
-
Save webserveis/0865d46bc0e385b51374e75bfc12d83d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void hackFixContentWithActionBar() { | |
int horizontalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, | |
2, getResources().getDisplayMetrics()); | |
int verticalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, | |
2, getResources().getDisplayMetrics()); | |
int topMargin=0; | |
TypedValue tv = new TypedValue(); | |
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { | |
topMargin = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); | |
} | |
LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent(); | |
root.setPadding(horizontalMargin, topMargin, horizontalMargin, verticalMargin); | |
/* Toolbar bar; | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { | |
LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent(); | |
bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false); | |
root.addView(bar, 0); // insert at top | |
} else { | |
ViewGroup root = (ViewGroup) findViewById(android.R.id.content); | |
ListView content = (ListView) root.getChildAt(0); | |
root.removeAllViews(); | |
bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false); | |
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(); | |
} | |
content.setPadding(0, height, 0, 0); | |
root.addView(content); | |
root.addView(bar); | |
}*/ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void setupActionBar() { | |
getLayoutInflater().inflate(R.layout.toolbar_settings, (ViewGroup)findViewById(android.R.id.content)); | |
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
ActionBar actionBar = getSupportActionBar(); | |
if (actionBar != null) { | |
// Show the Up button in the action bar. | |
actionBar.setDisplayHomeAsUpEnabled(true); | |
actionBar.setTitle(getString(R.string.settings_activity_title)); //Fix title after change locale | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment