简体   繁体   中英

Android appcompact doesn't show copy action from Contextual Action Bar for text selection

I faced with the weird issue.
When I use android holo theme as default theme, and then selecting text on webview, the contextual action bar show correctly.

<style name="MyTheme" parent="Theme.AppCompat.Light">   
</style>

在此输入图像描述

But when I use app compact holo theme, the select all and copy action are gone.

<style name="MyTheme" parent="android:Theme.Holo.Light">   
</style>

在此输入图像描述

Where is my problem? My app supports android devices 4.0+

Because in your menu.xml file you use atribute app:showAsAction="ifRoom" for not app commpat theme. Please change app:showAsAction="ifRoom" to android:showAsAction="ifRoom" and should work

Example

For this style

<style name="AppTheme" parent="android:Theme.Holo.Light">

works below menu

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      tools:context=".MainActivity">
    <item android:id="@+id/pase"
          android:title="@string/action_settings"
          android:orderInCategory="100"
          android:icon="@drawable/abc_ic_menu_paste_mtrl_am_alpha"
       //look here is a different
          android:showAsAction="ifRoom"/>
    <item android:id="@+id/copy"
          android:title="@string/action_settings"
          android:icon="@drawable/abc_ic_menu_copy_mtrl_am_alpha"
          android:orderInCategory="100"
          android:showAsAction="ifRoom"/>
    <item android:id="@+id/action_settings"
          android:title="@string/action_settings"
          android:orderInCategory="100"
          android:showAsAction="never"/>
</menu>

For this style

<style name="AppTheme" parent="Theme.AppCompat.Light">

works below menu

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      tools:context=".MainActivity">
    <item android:id="@+id/pase"
          android:title="@string/action_settings"
          android:orderInCategory="100"
          android:icon="@drawable/abc_ic_menu_paste_mtrl_am_alpha"
       //look here is a different
          app:showAsAction="ifRoom"/>
    <item android:id="@+id/copy"
          android:title="@string/action_settings"
          android:icon="@drawable/abc_ic_menu_copy_mtrl_am_alpha"
          android:orderInCategory="100"
          app:showAsAction="ifRoom"/>
    <item android:id="@+id/action_settings"
          android:title="@string/action_settings"
          android:orderInCategory="100"
          app:showAsAction="never"/>
</menu>

Additionally if you use Theme.AppCompat.Light you should use ActivityActionBar in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM