如何在Floating Action Mode中在Android 9上显示菜单项图标

如何在Floating Action Mode中在Android 9上显示菜单项图标,第1张

概述我有一个类似于以下的Android菜单XML:<item android:id='@+id/action_share' android:orderInCategory='100' android:icon='@drawable/ic_social_share' app:showAsAction='always' @H_403_0@

我有一个类似于以下的Android菜单XML:

<item    androID:ID="@+ID/action_share"    androID:orderIncategory="100"    androID:icon="@drawable/ic_social_share"    app:showAsAction="always"    androID:title="" /><item    androID:ID="@+ID/action_something_else"    androID:orderIncategory="200"    androID:icon="@drawable/ic_airplanemode_active_black_24dp"    app:showAsAction="always"    androID:title="" />

我的AndroID代码类似于:

   private voID startActionMode() {        startActionMode(new androID.vIEw.ActionMode.Callback2() {            @OverrIDe            public boolean onCreateActionMode(final androID.vIEw.ActionMode mode,final Menu menu) {                MenuInflater inflater = mode.getMenuInflater();                inflater.inflate(R.menu.main,menu);                mode.setTitle("floatING!!!!!");                return true;            }            @OverrIDe            public boolean onPrepareActionMode(final androID.vIEw.ActionMode actionMode,final Menu menu) {                return false;            }            @OverrIDe            public boolean onActionItemClicked(final androID.vIEw.ActionMode actionMode,final MenuItem menuItem) {                return false;            }            @OverrIDe            public voID onDestroyActionMode(final androID.vIEw.ActionMode actionMode) {            }        },androID.vIEw.ActionMode.TYPE_floatING);    }

当我将AndroID应用程序部署到AndroID 8设备时,浮动 *** 作模式会根据需要显示图标.

但是,当我将AndroID应用程序部署到AndroID 9设备时,浮动 *** 作模式为空,尽管有足够的空间放置图标,并且可以看到图标应位于的背景波纹效果.

如何在AndroID 9上使用androID.vIEw.ActionMode.TYPE_floatING并查看每个菜单项的图标?

我的gradle文件类似于:

apply plugin: 'com.androID.application'androID {    compileSdkVersion 28    buildToolsversion "28.0.3"    defaultConfig {        applicationID "org.research.development"        minSdkVersion 23        targetSdkVersion 28        versionCode 1        versionname "1.0"        testInstrumentationRunner "androIDx.test.runner.AndroIDJUnitRunner"    }    buildTypes {        release {            MinifyEnabled false            proguardfiles getDefaultProguardfile('proguard-androID.txt'),'proguard-rules.pro'        }    }}dependencIEs {    implementation filetree(dir: 'libs',include: ['*.jar'])    androIDTestImplementation('androIDx.test.espresso:espresso-core:3.1.0-Alpha4',{        exclude group: 'com.androID.support',module: 'support-annotations'    })    implementation 'androIDx.appcompat:appcompat:1.1.0-Alpha02'    implementation 'androIDx.constraintlayout:constraintlayout:1.1.3'    testImplementation 'junit:junit:4.12'}

这是我的申请方式

<!-- Base application theme. --><style name="Apptheme" parent="theme.AppCompat.light.DarkActionbar">    <!-- Customize your theme here. -->    <item name="androID:windowdisablePrevIEw">true</item>    <item name="windowActionbar">false</item>    <item name="androID:textcolorPrimary">@androID:color/white</item>    <item name="androID:textcolorSecondary">@androID:color/white</item>    <item name="actionMenuTextcolor">@androID:color/white</item>    <item name="androID:windowNoTitle">true</item>    <item name="colorPrimary">@color/colorPrimary</item>    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>    <item name="colorAccent">@color/colorAccent</item>    <!--  It should be true otherwise action mode will not overlay toolbar -->    <item name="windowActionModeOverlay">true</item>    <!--  For Custom Action Mode Background color/Drawable -->    <item name="actionModeBackground">@color/colorAccent</item></style><style name="Apptheme.NoActionbar">    <item name="windowActionbar">false</item>    <item name="windowNoTitle">true</item></style><style name="Apptheme.AppbarOverlay" parent="themeOverlay.AppCompat.Dark.Actionbar" /><style name="Apptheme.PopupOverlay" parent="themeOverlay.AppCompat.light" />
最佳答案
    class PrimaryActionModeCallback : ActionMode.Callback {    var onActionItemClickListener: OnActionItemClickListener? = null    private var mode: ActionMode? = null    @MenuRes private var menuResID: Int = 0    private var Title: String? = null    private var subTitle: String? = null    overrIDe fun onCreateActionMode(mode: ActionMode,menu: Menu): Boolean {        this.mode = mode        mode.menuInflater.inflate(menuResID,menu)        mode.Title = Title        mode.subTitle = subTitle        return true    }    overrIDe fun onPrepareActionMode(mode: ActionMode,menu: Menu): Boolean {        return false    }    overrIDe fun onDestroyActionMode(mode: ActionMode) {        this.mode = null    }    overrIDe fun onActionItemClicked(mode: ActionMode,item: MenuItem): Boolean {        onActionItemClickListener?.onActionItemClick(item)        mode.finish()        return true    }    fun startActionMode(vIEw: VIEw,@MenuRes menuResID: Int,Title: String? = null,subTitle: String? = null) {        this.menuResID = menuResID        this.Title = Title        this.subTitle = subTitle        vIEw.startActionMode(this)    }    fun finishActionMode() {        mode?.finish()    }}@RequiresAPI(Build.VERSION_CODES.M)    class floatingActionModeCallback : ActionMode.Callback2() {    var onActionItemClickListener: OnActionItemClickListener? = null    private var mode: ActionMode? = null    @MenuRes private var menuResID: Int = 0    private var contentleft: Int = 0    private var contenttop: Int = 0    private var contentRight: Int = 0    private var contentBottom: Int = 0    overrIDe fun onCreateActionMode(mode: ActionMode,menu)        return true    }    overrIDe fun onPrepareActionMode(mode: ActionMode,item: MenuItem): Boolean {        onActionItemClickListener?.onActionItemClick(item)        mode.finish()        return true    }    overrIDe fun onGetContentRect(mode: ActionMode,vIEw: VIEw,outRect: Rect) {        outRect.set(contentleft,contenttop,contentRight,contentBottom)    }    fun startActionMode(vIEw: VIEw,contentleft: Int = 0,contenttop: Int = 0,contentRight: Int = vIEw.wIDth,contentBottom: Int = vIEw.height) {        this.menuResID = menuResID        this.contentleft = contentleft        this.contenttop = contenttop        this.contentRight = contentRight        this.contentBottom = contentBottom        vIEw.startActionMode(this,ActionMode.TYPE_floatING)    }    fun finishActionMode() {        mode?.finish()    }}interface OnActionItemClickListener {    fun onActionItemClick(item: MenuItem)}// Start primary ActionModeval primaryActionModeCallback = PrimaryActionModeCallback()primaryActionModeCallback.startActionMode(vIEw,R.menu.menu_actions,"Title","SubTitle")// Start floating ActionModeif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {    val floatingActionModeCallback = floatingActionModeCallback()    floatingActionModeCallback.startActionMode(vIEw,x,y,wIDth,height)}                   

You can get description from here,正在通过一些修改在我的项目上工作. 总结

以上是内存溢出为你收集整理的如何在Floating Action Mode中在Android 9上显示菜单项图标 全部内容,希望文章能够帮你解决如何在Floating Action Mode中在Android 9上显示菜单项图标 所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1145054.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存