Android showcaseview试图让圈子更小

时间:2014-12-13 17:42:22

标签: android showcaseview

我试图找到一些信息,但到目前为止,对我来说没有任何作用。

当我尝试这样做时: 新的ShowcaseView.Builder(getActivity(),true)

外面2发光的圆圈消失了,其他两个圆圈失去了颜色。只有按钮才能保持正确的颜色。

Dimens.xml

<dimen name="showcase_radius">40dp</dimen>
<dimen name="showcase_radius_inner">44dp</dimen>
<dimen name="showcase_radius_outer">48dp</dimen>

Styles.xml

<style name="CustomShowcaseTheme">
        <item name="sv_backgroundColor">#CC000000</item>
        <item name="sv_buttonText">Close</item>
        <item name="sv_tintButtonColor">true</item>
        <item name="sv_titleTextAppearance">@style/CustomTitle</item>
        <item name="sv_detailTextAppearance">@style/TextAppearance.ShowcaseView.Detail</item>
</style>

<style name="CustomTitle" parent="TextAppearance.ShowcaseView.Title">
        <item name="android:textColor">#ffffff</item>
</style>

<style name="TextAppearance.ShowcaseView.Detail" parent="android:style/TextAppearance">
        <item name="android:textColor">#FFFFFF</item>
</style>

示例 - 如您所见,没有默认颜色,外圈消失了:

enter image description here

使用相同的设置,但使用新的ShowcaseView.Builder(getActivity()),内部圆圈变得更小但其他人不遵循它但是它们保持原样。 enter image description here

是否有任何解决方案可以让它们变得更小但看起来与默认圆圈完全相同?

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我发现了一个&#34;解决方案&#34;这对我有用,但也许不是正确的方法。这对作者来说有点晚了,但也许对其他人来说仍然有用。

  1. 这个发光的圆圈是一个名为 cling_bleached.png 的图像。找到它(drawable-xhdpi文件夹)和调整大小(从800x800到400x400)

  2. showcase_radius设置为47 (原始94的一半)。不要改变另外两个半径。

  3. 不要在ShowcaseView.Builder中使用true

答案 1 :(得分:0)

这是我使用的解决方案

我更喜欢它,因为不会修改 ShowcaseView 的原始来源

但它使用反射

  1. 首先将任何所需的值设置为资源xml,如

    <dimen name="sv_radius">40dp</dimen>
    
  2. 使用此方法创建ShowcaseView.Builder的实例

        private ShowcaseView.Builder createShowcaseViewBuilder() {
    
            ShowcaseView.Builder showcaseViewBuilder = new ShowcaseView.Builder(activity, true)
                    /**
                     * set theme
                     */
                    .setStyle(R.style.ShowcaseTheme4);
            /**
             * Load the new radius from resource xml
             */
            float radius = activity.getResources().getDimension(R.dimen.sv_radius);
    
            try {
                Field showcaseViewField = ShowcaseView.Builder.class.getDeclaredField("showcaseView");
                showcaseViewField.setAccessible(true);
                Object showcaseViewObject = showcaseViewField.get(showcaseViewBuilder);
                Field showcaseDrawerField = ShowcaseView.class.getDeclaredField("showcaseDrawer");
                showcaseDrawerField.setAccessible(true);
                Object showcaseDrawerObject = showcaseDrawerField.get(showcaseViewObject);
    
                Field innerRadiusField = null;
                try {
                    innerRadiusField = showcaseDrawerObject.getClass().getDeclaredField("innerRadius");
                } catch (NoSuchFieldException e) {
                    e.printStackTrace();
                }
                if (null != innerRadiusField) {
                    /**
                     * detected that the new showcase-drawer is used
                     */
                    innerRadiusField.setAccessible(true);
    
                    Field outerRadiusField = showcaseDrawerObject.getClass().getDeclaredField("outerRadius");
                    outerRadiusField.setAccessible(true);
    
                    float oldInnerRadius = (float) innerRadiusField.get(showcaseDrawerObject);
                    float oldOuterRadius = (float) outerRadiusField.get(showcaseDrawerObject);
                    float newOuterRadius = radius * (oldOuterRadius / oldInnerRadius);
    
                    innerRadiusField.set(showcaseDrawerObject, radius);
                    outerRadiusField.set(showcaseDrawerObject, newOuterRadius);
                } else {
                    /**
                     * detected that the old showcase-drawer is used (no outer radius)
                     */
                    Field showcaseRadiusField = showcaseDrawerObject.getClass().getDeclaredField("showcaseRadius");
                    showcaseRadiusField.setAccessible(true);
                    showcaseRadiusField.set(showcaseDrawerObject, radius);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return showcaseViewBuilder;
        }