Home > database >  Pixelated border as an android style xml
Pixelated border as an android style xml

Time:01-07

I am trying to create a theme/style for my buttons in my android layout. I want to create a style where the corners are curved but are also pixelated (To fit the theme of my app) but also respects the text inside by keeping the text inside its borders.

I was able to create this type of pixelated border in javascript/css.

.pixelated {
    position: relative;
    display: inline-block;
    padding: 1rem 1.25rem;
    border-radius: 20px;
    border-style: solid;
    border-width: 4px;
    border-color: black;
    border-image-slice: 4;
    border-image-width: 2;
    border-image-outset: 0;
    border-image-source: url('data:image/svg xml;charset=UTF-8,
  
');
    // The SVG:
    // <svg xmlns='http://www.w3.org/2000/svg' width='12' height='12'>
    //   <path d='M2 2h2v2H2zM4 0h2v2H4zM10 4h2v2h-2zM0 4h2v2H0zM6 0h2v2H6zM8 2h2v2H8zM8 8h2v2H8zM6 10h2v2H6zM0 6h2v2H0zM10 6h2v2h-2zM4 10h2v2H4zM2 8h2v2H2z' fill='#000' />
    // </svg>
}
<div >A Button</div>
<div >A Longer Button</div>
<div >An Even Longer Button</div>

I was wondering if its possible to recreate something similar to this javascript/css as an xml style/theme to be used in an android layout. If this cant be re-created as an android style, could this be made programmatically with java?

Thank you!

CodePudding user response:

Android has an equivalent to those sort of CSS borders.

They are called NinePatch images.

You should be able to convert them easily enough.

  •  Tags:  
  • Related