android - Toolbar when extending Activity -


i need extend activity , not actionbaractivity or appcompatactivity in order use third party library.

in app i've been using appcompatactivity in order add toolbar in it, apparently cannot same if extend activity. i'd happy have actionbar: it's not same, it's better nothing. still, don't know how :-/

do have advice me? know it's silly question don't know how make work...

first of check library using. can outdated.

with new 22.1+ appcompat can use appcompatdelegate extend appcompat's support activity.

you can check official link appcompatpreferenceactivity, can find example of technique.

you have :

  • to add toolbar activity:

something this:

<android.support.v7.widget.toolbar     android:id="@+id/mytoolbar"     android:background="?attr/colorprimary"/> 
  • to use appcompat theme without actionbar.

something this:

  <style name="apptheme" parent="theme.appcompat.noactionbar">         <item name="colorprimary">@color/mycolor</item>         ....     </style> 
  • add appcompatdelegate activity

something like:

public class mainactivity extends activity implements appcompatcallback {        private appcompatdelegate delegate;          @override         protected void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);              //create delegate                     delegate = appcompatdelegate.create(this, this);              //call oncreate() of appcompatdelegate             delegate.oncreate(savedinstancestate);              //use delegate inflate layout             delegate.setcontentview(r.layout.activity_main);              //add toolbar             toolbar toolbar= (toolbar) findviewbyid(r.id.mytoolbar);             delegate.setsupportactionbar(toolbar);         }     //..... } 

check official example wrap other methods of activity have full compatibility appcompatactivity.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -