how to design layout button to be half one color, half other

I need to design button for android app to be rectangle, and to be half one color, half other. In XML of course.

I have tried this:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<padding
    android:left="7dp"
    android:top="15dp"
    android:right="7dp"
    android:bottom="15dp" />
<gradient
    android:startColor="#a241cb"
    android:endColor="#a241cb"
    android:type="linear"
    android:angle="90"/>
<stroke>
    android:width="1dip"
    android:color="#a241cb" />
<corners android:radius="0dp" />
</shape>

Any help is appreciated

Answers


Using a 9 patch like this (save it in your drawable folder as bw_bg.9.png):

You can get a result like this:

Example layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f00f"
    >
    <Button
        android:layout_width="120dp"
        android:layout_height="60dp"
        android:layout_centerInParent="true"
        android:background="@drawable/bw_bg"
    />
</RelativeLayout>

Don't mind the size (it's running on a Froyo 2.8 inch screen). Also don't mind the notification (it's from another running app).


Try this:

frist create background.xml in drwable folder

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#4A225E"
        android:endColor="#4C4064"
        android:centerColor="#B4AFC5"/>
</shape>

and then set button backgrond its work for me


you can achieve this by using gradients as background. use this create a new XML file under res/drawable folder and name it as button_bg.xml. button_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
  <gradient
      android:startColor="#D5DDE0"
      android:centerColor="#e7e7e8"
      android:endColor="#CFCFCF"
      android:angle="270" />
</shape>

now use it for your Button like this:

android:background="@drawable/button_bg"

Hope it helps. :)


Need Your Help

Equals method of System.Collections.Generic.List<T>...?

c# .net list equals

I'm creating a class that derives from List...

Converting Timestamp observable to YEAR-MONTH-DAY format for polymer Dart

timestamp dart polymer

What the title states. I am calling a cloud endpoint that records the submission time of a record as a Java Date. When I call for the record form this endpoint it returns it to Dart as a timestamp