2014-12-13 98 views
0

我认为这与proguard有关;请参阅帖子底部的修改。分享按钮在导出应用后更改颜色

我使用eclipse来构建一个小的Android应用程序。

当我运行我的应用程序(通过点击Eclipse中的绿色运行按钮,用我的手机连接到由USB我的电脑),我的分享按钮看起来是这样的:

white share button

..这是我想要的。

当我文件 - >导出我的应用程序并安装使用adb install的APK(或者如果我上传新的APK Play商店并安装更新),我的分享按钮看起来是这样的:

black share button

〜不幸。

如何让按钮在导出的应用程序中显示为白色?

从我的代码的某些代码段:

菜单项:

<item 
    android:id="@+id/menu_item_share" 
    android:title="@string/action_share" 
    mysapp:showAsAction="ifRoom" 
    myapp:actionProviderClass="android.support.v7.widget.ShareActionProvider" /> 

我RES /价值/ styles.xml:

<!-- 
    Base application theme, dependent on API level. This theme is replaced 
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 
--> 
<style name="AppBaseTheme" parent="Theme.AppCompat.Light"> 
    <!-- 
     Theme customizations available in newer API levels can go in 
     res/values-vXX/styles.xml, while customizations related to 
     backward-compatibility can go here. 
    --> 
</style> 

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
     <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
</style> 

<style name="vertical_space"> 
    <item name="android:layout_marginTop">10dp</item> 
</style> 

资源/ VA梅毒-V14/styles.xml:

<!-- 
    Base application theme for API 14+. This theme completely replaces 
    AppBaseTheme from BOTH res/values/styles.xml and 
    res/values-v11/styles.xml on API 14+ devices. 
--> 
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- API 14 theme customizations can go here. --> 
</style> 

我也有一个parent="Theme.AppCompat.Light.DarkActionBar"值-V11/styles.xml。我没有值-V21目录。

编辑1

我试图想导出应用程序而不是只从Eclipse中运行它时,什么样的变化。

一种可能性是,我在project.properties启用的ProGuard:导出时

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 

Proguard的只有积极的,对不对?不知道这是否可以解释。

编辑2

我在project.properties注释掉proguard.config线和问题消失,即共享按钮导出该应用时是白色的。不过,我希望启用proguard。我怎样才能启用proguard并在导出时保持按钮为白色?

+0

你能否提供apk的错误,指向保管箱或其他东西的链接? – gio 2014-12-17 17:40:38

+0

@gio在我的用户页面中,您将看到一个Play商店链接,该链接指向带有黑暗分享按钮的应用版本。这有帮助吗? – Adrian 2014-12-18 10:59:55

+0

它包含错误吗? – gio 2014-12-18 11:01:09

回答

1

不知道为什么你会看到这一行为。但是,您可以尝试明确定义共享drawable的色调颜色。事情是这样的:

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    <!-- Defining actionModeShareDrawable is not really required 
    <item name="android:textColorSecondary">#b3ffffff</item> 
</style> 

从我可以告诉,通过属性textColorSecondary引用的颜色用于着色份额绘制。所以,明确颜色可能会解决您的问题。如果你想让我提到我如何挑选这个属性(我还没有测试它是否可行:)),请告诉我。

编辑

浏览到文件夹(SDK安装)/演员/安卓/支持/ V7 /程序兼容性/ RES /绘制-xhdpi。

复制abc_ic_menu_share_mtrl_alpha.png并将其粘贴到您的应用程序的res/drawable-xhdpi文件夹。将其名称更改为 - changed_menu_share.png

你的主题,现在应该是这样的:

<!-- Application theme. --> 
<style name="AppTheme" parent="AppBaseTheme"> 
    <!-- All customizations that are NOT specific to a particular API-level can go here. --> 
    <item name="actionModeShareDrawable">@drawable/changed_menu_share</item> 
</style> 

这应该使Tintmanager忽略此绘制也就是说,它永远是你想要的颜色 - 而且,在这种情况下,#FFFFFF。另请注意,我们不再覆盖textColorSecondary属性。

+0

感谢您的建议。我在导出时会导致分享按钮变成白色,但它引入了一个新问题:我的EditTexts过去有一个漂亮的绿色下划线,现在只要我滑动到新的片段就从白色切换到绿色。 – Adrian 2014-12-18 10:54:33

+0

@Adrian当然可以。但是,这个小测试表明你遇到的问题是 - 在某种程度上,框架提供了'textColorSecondary'的值为'#8a000000',而不是'#b3ffffff'。让我看看这个并回复你。 – Vikram 2014-12-18 11:01:05

+0

@Adrian看完'TintManager'类之后,我确信它使用了从属性'actionModeShareDrawable'获取的drawable的资源ID。如果我们不在我们的主题中重写此属性,则默认为'R.drawable.abc_ic_menu_share_mtrl_alpha'。所以,为了防止这种情况,我们可以指定另一个可绘制的 - TintManger将忽略它。 – Vikram 2014-12-18 11:55:52

1

基于外观它不应该是

<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
<!-- 
    Theme customizations available in newer API levels can go in 
    res/values-vXX/styles.xml, while customizations related to 
    backward-compatibility can go here. 
--> 
</style> 
+0

刚刚尝试过,我得到和以前一样的行为:当我从eclipse运行应用程序时,按钮是白色的,但是当我手动导出并安装apk时,按钮是黑色的。 – Adrian 2014-12-13 14:42:33

+0

您是否尝试清洁该项目? – 2014-12-13 15:19:35

+0

刚刚尝试清洁和再出口,没有变化。 – Adrian 2014-12-13 15:36:45