Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can use xmlns on styles to define cardView corner radius?

I wanna make something like this:

<style name="cardViewInfo">
    <item name="android:layout_marginLeft">@dimen/small_padding_card_view</item>
    <item name="android:layout_marginRight">@dimen/small_padding_card_view</item>
    <item name="android:layout_marginBottom">@dimen/small_padding_card_view</item>
    <item name="android:layout_marginTop">@dimen/large_padding_card_view</item>
    <item name="card_view:cardCornerRadius">2dp</item>
</style>

But I have problems with the name card_view thats is not definded, my question is if I can make something like on the layout's to use this namespace:

xmlns:card_view="http://schemas.android.com/apk/res-auto"

Best regards.

like image 652
Vinicius DSL Avatar asked Apr 21 '15 14:04

Vinicius DSL


People also ask

When should I use CardView?

CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation. CardView is the view that can display views on top of each other. The main usage of CardView is that it helps to give a rich feel and look to the UI design.

What is cardCornerRadius?

card view:cardCornerRadius - This attribute is used to set the corner radius for the CardView. card_view:cardElevation - This attribute is used to set the elevation for the CardView. The elevation is used to show the shadow of the CardView.

What is Android Card elevation?

Note that the card_view:cardElevation is used to determine the size and softness of the shadow so as to realistically depict the depth. These properties can be set programmatically as well: CardView card = ... card.


1 Answers

So, although this isn't exactly a custom style, it IS a property outside of the android xmlns (XML Namespace).

I found that this works for me.

<resources>
    <style name="StyleName" parent="CardView.Light">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:elevation">50dp</item>
        <item name="android:paddingLeft">6dip</item>
        <item name="android:paddingRight">6dip</item>
        <item name="cardUseCompatPadding">true</item>
        <item name="cardBackgroundColor">#fff</item>
        <item name="cardCornerRadius">6dp</item>
    </style>
</resources>

If you have any other errors, can you please post them as an edit to your original question.

like image 58
tyler Avatar answered Oct 02 '22 15:10

tyler