Вопрос

Is it possible to have POPUP menu like play store attached to each row of adapter what i done so far

holder.rl_overflow.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                PopupMenu popup = new PopupMenu(context, holder.rl_overflow);
                popup.getMenuInflater().inflate(R.menu.overflow, popup.getMenu());  

                popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        Toast.makeText(context,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();
                        return false;
                    }
                });
                popup.show();

            }
        });

but constructor for POPUP menu says its available from API 11. I go through the developers.android.com and i found, its can be added using SUPPORT V7 library "https://developer.android.com/reference/android/support/v7/widget/PopupMenu.html" but i'm not able to implement this using ABS, please help someone.

Это было полезно?

Решение

Use like this PopupMenu in ActionBarSherlock.

Styling of the PopupMenu -

<item name="popupMenuStyle">@style/PopupMenu.MyAppTheme</item>      

<style name="PopupMenu.MyAppTheme" parent="@style/Widget.Sherlock.ListPopupWindow">
    <item name="android:popupBackground">@android:color/white</item>
</style>

Другие советы

If you are using the support library you should discard using the ABS. Instead, import the support library into your workspace which can be found in ~/adt-bundle-linux-x86_64-20130729/sdk/extras/android/support/v7/appcompact and use is in your project. And also don't forget to add the support library which can be brought up right clicking into your project and entering Android Tools -> Add Support Library

Using appcompact you will have to extend your activity class with ActionBarActivity. And also using the appcompact you have to make changes in your styles folder. You could refer to this. Do not also forget to update the values-v11 and values-v14 file. Doing all of this will make your application compatible.

P.S. If any error occurs in your appcompact library. Don't panic look at the error logs and open the file that seems to contain the error. Most probably you will have to refresh the file and after that you just fix project properties, and the error goes away.

Hope this helps :)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top