使用工具栏时,无法风格的动作模式 [英] Unable to style action mode when using Toolbar

查看:73
本文介绍了使用工具栏时,无法风格的动作模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这是否是一个错误或由于某种原因,我没有使用新的工具栏类正常。

我能够在动作条直接使用可用的主题之一成功的主题。这也让我的主题ActionMode。一切都运行完美预期。下面是我怎么做。

 <样式名称=Theme.ActionBar父=@风格/ Theme.AppCompat.Light.DarkActionBar>
        <项目名称=actionModeBackground> @可绘制/ action_mode_background< /项目>
< /风格>
 

现在我正在寻找多一点的灵活性,所以我试图用新的工具栏从支持库。完美的工具栏实现,做工精细,不过,现在的操作模式,不再按预期工作。自定义背景没有工作,操作模式栏按下工具栏了下来。

要解决这个倒推的问题,我用的标志 windowActionModeOverlay 。对我来说,事实行为模式不会成为工具栏的一部分,吸...:/

 <样式名称=Theme.ActionBar父=@风格/ Theme.AppCompat.Light.DarkActionBar>
        <项目名称=windowActionBar>假< /项目>
        <项目名称=windowActionModeOverlay>真< /项目>
        <项目名称=actionModeBackground> @可绘制/ action_mode_background< /项目>
< /风格>
 

在我的活动我这样做让我的工具栏默认动作条。

 工具栏=(栏)findViewById(R.id.toolBar);
setSupportActionBar(工具栏);
 

现在我已经尝试了这么多的事情。我甚至尝试潜入源弄清楚到底是怎么回事。

任何想法,为什么发生这种情况?我怎样才能样式的ActionMode?或者更确切地说我怎样才能改变ActionMode的背景是什么?


更新1
我注意到,当添加<项目名称=windowActionBar>假< /项目> 来我的活动主题的动作模式失去其主题与有它是真实的。显然,其设置为true时将包括窗口操作栏。


更新2
我能得到正确的主题用一对夫妇MODS的操作模式。

  1. 的操作模式背景。原来你只要直接在ActionMode主题设置背景为机器人:背景!此外,该文本需要的主题指定。

    <项目名称=actionModeStyle> @风格/ Widget.ActionMode< /项目>
    <样式名称=Widget.ActionMode父=@风格/ Widget.AppCompat.ActionMode>       <项目名称=机器人:背景> @可绘制/ action_mode_background< /项目>       <项目名称=titleTextStyle> @风格/ TitleTextStyle< /项目> < /风格>

  2. 返回箭头没有得到风格。我重写使用的绘制,只是加了我自己的白色。
    <项目名称=actionModeCloseDrawable> @可绘制/ ic_arrow_back_white_24dp< /项目>

解决方案

嗯,我终于能够通过一些样式,主题,ATTRS,和$ C $从支持库C挖后正确样式的操作模式。

在我公司提供的解决方案,我的问题,我不得不提到,似乎有要与支持库中的错误。看来,当你隐藏窗口操作栏松动设定主题的动作模式。我报告了错误< /一>,看看他们解决这个问题或提供更多的细节。

所以,解决办法是基本样式的背景,文本和关闭按钮,我的自我。用我自己的ActionMode风格和更改属性指向的关闭图标执行该操作需要。

的themes.xml

 &LT;样式名称=Theme.Main.Home&GT;
     &LT;项目名称=windowActionModeOverlay&GT;真&LT; /项目&GT;
     &LT;项目名称=actionModeStyle&GT; @风格/ Widget.ActionMode&LT; /项目&GT;
     &LT;项目名称=actionModeCloseDrawable&GT; @可绘制/ ic_arrow_back_white_24dp&LT; /项目&GT;
&LT; /风格&GT;
 

styles.xml

 &LT;样式名称=Widget.ActionMode父=@风格/ Widget.AppCompat.ActionMode&GT;
    &LT;项目名称=机器人:背景&GT; @可绘制/ action_mode_background&LT; /项目&GT;
    &LT;项目名称=titleTextStyle&GT; @风格/ TitleTextStyle&LT; /项目&GT;
&LT; /风格&GT;
 

  • 背景
    这是棘手,因为 actionModeBackground 不用于设置操作模式的后台工作。你必须通过标准安卓更改背景:在ActionMode风格背景
  • 标题文本
    只需提供一个大将风范的titleTextStyle允许改变文字颜色。
  • 关闭图标
    下载的材料图标,并使用 actionModeCloseDrawable ATTR添加的关闭图标我自己。

I'm not sure if this is a bug or somehow I'm not using the new Toolbar class properly.

I'm able to successfully theme the ActionBar directly using one of the available themes. This also allows me to theme the ActionMode. Everything works perfect as expected. Here is how I'm doing that.

<style name="Theme.ActionBar" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="actionModeBackground">@drawable/action_mode_background</item>
</style>

Now I'm looking for a little more flexibility so I'm trying to use the new Toolbar from the support library. Perfect the Toolbar implemented and working fine, however, now the action mode no longer working as expected. The custom background not working and the action mode bar is pushing the Toolbar down.

To fix the pushing down issue I used the flag windowActionModeOverlay. To me the fact that the action mode doesn't become part of the Toolbar sucks... :/

<style name="Theme.ActionBar" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowActionModeOverlay">true</item>
        <item name="actionModeBackground">@drawable/action_mode_background</item>
</style>

In my Activity I do the following to make my Toolbar the default ActionBar.

Toolbar toolbar = (Toolbar) findViewById(R.id.toolBar);
setSupportActionBar(toolbar);

Right now I have tried so many things. I even tried diving into the source to figure out what is going on.

Any ideas why this is happening? How can I style the ActionMode? Or more specifically how can I change the background of the ActionMode?


Update 1
I noticed that when adding <item name="windowActionBar">false</item> to my activity theme the action mode looses its theme versus having it as true. Obviously setting it as true it would include the window action bar.


Update 2
I was able to get the action mode themed properly using a couple mods.

  1. The action mode background. Turns out you just set the background directly on the ActionMode theme as android:background! Also, the text you need to specify it on the theme.

    <item name="actionModeStyle">@style/Widget.ActionMode</item>
    <style name="Widget.ActionMode" parent="@style/Widget.AppCompat.ActionMode"> <item name="android:background">@drawable/action_mode_background</item> <item name="titleTextStyle">@style/TitleTextStyle</item> </style>

  2. The back arrow not getting styled. I overwrote the drawable used and just added my own in white.
    <item name="actionModeCloseDrawable">@drawable/ic_arrow_back_white_24dp</item>

解决方案

Well, I was finally able to properly style the action mode after digging through some styles, themes, attrs, and code from the support library.

Before I provide the solution to my question I have to mention that there seems to be a bug with the support library. It seems to loose the set theme for the action mode when you hide the window action bar. I have reported a bug to see if they fix this or provide more details.

So the solution was to essentially style the background, text, and close icon my self. Doing this required using my own ActionMode style and changing an attribute pointer to the close icon.

themes.xml

<style name="Theme.Main.Home">
     <item name="windowActionModeOverlay">true</item>
     <item name="actionModeStyle">@style/Widget.ActionMode</item>
     <item name="actionModeCloseDrawable">@drawable/ic_arrow_back_white_24dp</item>
</style>

styles.xml

<style name="Widget.ActionMode" parent="@style/Widget.AppCompat.ActionMode">
    <item name="android:background">@drawable/action_mode_background</item>
    <item name="titleTextStyle">@style/TitleTextStyle</item>
</style>

  • Background
    This was tricky because actionModeBackground doesn't work for setting the background of the action mode. You must change the background via the standard android:background on the ActionMode style.
  • Title text
    Simply providing a general style for the titleTextStyle allowed changing the text color.
  • Close icon
    Downloaded the materials icons and added the close icon my self using the actionModeCloseDrawable attr.

这篇关于使用工具栏时,无法风格的动作模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆