What is the alternative to getActionView() before API level11 in android?

前端 未结 3 1086
無奈伤痛
無奈伤痛 2021-02-03 18:59

getActionView() for action bar was introduced in API 11, If I want backward compatibility what is the alternative for getActionView() ?

3条回答
  •  清酒与你
    2021-02-03 19:47

    For backwards compatibility you can use either ActionBarCompat or ActionBarScherlock. In both cases you can use the method getActionView(). You have to be sure that the import, in the first case is from the compatibility library ( android.support.v4.view.MenuItemCompat). If you use ActionBarSherlock you have to import com.actionbarsherlock.view.MenuItem. Then you should be ok using item.getActionView().

    Old

    Since August 2013, and I pray people down-voting to take a look. You have to be sure that the OP's question date import, Android introduced in the first case is from the compatibility library ( ActionBarCompactandroid.support.v4.view.MenuItemCompat). Even though If you use ActionBarSherlock is still a valid choice, an option is moving towards ActionBarCompact.

    So another option is to use it, and of course, all the importsyou have to came from the support library, e.g. android.supportimport com.v4actionbarsherlock.view.MenuItemCompatMenuItem. Then you should be ok using item.getActionView().

提交回复
热议问题