AviranAbady/CookieBar2

i need set backgroundDrawable when i use setCustomView

manondidi opened this issue · 5 comments

only find setBackgroundColor when i use setCustomView, if i set android:background="@drawable/publish_snack_success_bg"
in my custom_layout.xml,its background will be setted by defaultbgcolor

ok,i use these code to make backgroundDrawable
`

<View
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/publish_snack_success_bg"
    />

<LinearLayout
    android:id="@+id/btnAction"
    android:layout_width="55dp"
    android:layout_height="26dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:layout_marginRight="15dp"
    android:layout_marginBottom="20dp"
    android:background="@drawable/publish_snack_btn_bg"
    android:gravity="center"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="查看"
        android:textColor="#ffffffff"
        android:textSize="13sp" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="4dp"
        android:src="@drawable/publish_snack_arrow" />
</LinearLayout>

<TextView
    android:id="@+id/tvTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@id/btnAction"
    android:layout_alignBottom="@id/btnAction"
    android:layout_marginLeft="16dp"
    android:gravity="center_vertical"
    android:text="发布成功"
    android:textColor="#ffffffff"
    android:textSize="16dp"
    android:textStyle="bold" />

<FrameLayout
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:visibility="gone">

    <ImageView
        android:id="@+id/iv_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tv_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/btn_action"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</FrameLayout>

`

CookieBar.build(Smart.getApp().currentResumedActivity)
.setBackgroundColor(R.color.transparent_color)
.setCustomView(R.layout.layout_publish_fail_snackbar)
.setAnimationIn(R.anim.anim_top_snack_in, R.anim.anim_top_snack_in)
.setAnimationOut(R.anim.anim_top_snack_out, R.anim.anim_top_snack_out)
.setCustomViewInitializer {
val btnAction = it.findViewById(R.id.btnAction)
val tvTitle = it.findViewById(R.id.tvTitle)
btnAction.setOnClickListener {
retryEdit()
}
}
.setEnableAutoDismiss(true) // Cookie will stay on display until manually dismissed
.setSwipeToDismiss(true) // Deny dismiss by swiping off the view
.setCookiePosition(CookieBar.TOP)
.setDuration(4000)
.show()

Thanks @manondidi , it is a bug.

In the next version I will make sure that in case of custom layout the default bg is not being applied.

in custom layout why i must have your define id??
if can not find just let it go

<ImageView
    android:id="@+id/iv_icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/tv_title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/tv_message"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/btn_action"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

@manondidi

The issue has been raised before, future releases will not enforce 'cookie integrity' as being done currently, you can bypass the issue by adding the views you dont need and set their visibility to `View.GONE

Fixed background color override on custom layouts
Removed cookie view integrity check for custom layout
Changes made in the following commit