Skip to content

Instantly share code, notes, and snippets.

@budioktaviyan
Created December 26, 2016 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save budioktaviyan/f24fde2024f4b38686223fa780baa27d to your computer and use it in GitHub Desktop.
Save budioktaviyan/f24fde2024f4b38686223fa780baa27d to your computer and use it in GitHub Desktop.
Main Activity Class
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_main);
toolbar.setTitle(getResources().getString(R.string.app_name));
toolbar.setPadding(0, getStatusBarHeight(), 0, 0);
setSupportActionBar(toolbar);
}
private int getStatusBarHeight() {
final int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
return resourceId > 0 ? getResources().getDimensionPixelSize(resourceId) : 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment