Maddie_J February 2016

How to replace Sherlock ActionBar in with AppCompat

I have an old project in eclipse which uses the Sherlock actionbar, however I would like to replace this actionbar with AppTheme or AppCompat actionbar. I want the actionbar to have the same features such as, dropdown list view. Please help.

public class MainActivity extends SherlockActivity implements ActionBar.OnNavigationListener,
        OnItemClickListener {

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);


        Context context = getSupportActionBar().getThemedContext();
                R.layout.sherlock_spinner_item);
        list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

        getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        getSupportActionBar().setListNavigationCallbacks(list, this);

Answers


Illya Bublyk February 2016

Use Toolbar from support design library and AppCompatActivity

public class MainActivity extends AppCompatActivity {
    @Override
protected void onCreate(Bundle savedInstanceState) {
    Toolbar toolbar = findViewById(R.id.toolbar)
    setSupportActionBar(toolbar);
 }

}

And add <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary"/>

in R.layout.activity_main

Post Status

Asked in February 2016
Viewed 1,989 times
Voted 7
Answered 1 times

Search




Leave an answer