hi @mikepenz i want use one drawer in all activity
but i dont want copy and paste codes in all activity
can you help me ?
You can either make an abstract activity that implements the drawer and then make the other activities extend from that one or have one activity and use fragments.
@kakai248 can you show me in example ? thanks
For extending you could do something like this:
public abstract class BaseActivity extends AppCompatActivity {
protected Drawer drawer;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawer = new DrawerBuilder()
.withActivity(this)
.addItems(...)
.build();
}
}
And then each activity extends the base activity:
public class MainActivity extends BaseActivity {
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// you can access the drawer here because it was initialized in super
}
}
For fragments you have one activity that uses the drawer and then the actual content is displayed on a fragment. For this option you better go check the Android documentation.
@kakai248 thanks
but not work
can you show me in a sample ?
thank u so much
@kakai248 thanks for answering.
@armoun the answer given by @kakai248 is the basic implemenation what to do. It's no running sample. If you need help on how to get a base activity working you can try to search on stackoverflow or other sites, as this is nothing lib specific
Most helpful comment
@kakai248 thanks for answering.
@armoun the answer given by @kakai248 is the basic implemenation what to do. It's no running sample. If you need help on how to get a base activity working you can try to search on stackoverflow or other sites, as this is nothing lib specific