Last active
September 11, 2018 19:32
-
-
Save jandrop/840c6dde6f24568f6e5d54154748d74c to your computer and use it in GitHub Desktop.
Base Activity with toolbar
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
package es.atrapandocucarachas.activity; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.Toolbar; | |
import es.atrapandocucarachas.R; | |
/** | |
* @author Alejandro Platas Mallo | |
* @version 1.00 | |
* @since 18/5/15 | |
*/ | |
public abstract class BaseActivity extends AppCompatActivity { | |
private Toolbar toolBar; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(getLayoutResource()); | |
toolBar = (Toolbar) this.findViewById(R.id.toolbar); | |
if (toolBar != null) { | |
setSupportActionBar(toolBar); | |
if (getSupportActionBar() != null) { | |
setDisplayHomeEnabled(true); | |
} | |
} | |
} | |
protected abstract int getLayoutResource(); | |
public void setDisplayHomeEnabled(boolean b) { | |
if (getSupportActionBar() != null) { | |
getSupportActionBar().setDisplayHomeAsUpEnabled(b); | |
} | |
} | |
@Override | |
public void setTitle(CharSequence title) { | |
toolBar.setTitle(title); | |
} | |
@Override | |
public void setTitle(int titleId) { | |
toolBar.setTitle(titleId); | |
} | |
public Toolbar getToolBar() { | |
return toolBar; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment