white text and black background using xml code android
How to fill the background efficiently with white text and black background.when i fill the backgound using this code in xml in Button filed
android:background="#c6010101"
Button code is here
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/OpenBraces"
android:id="@+id/buttonOB"
android:layout_above="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:layout_toEndOf="@+id/button1"
android:background="#c6010101"
android:textColor="#FFFFFCFC" />
Full code is here.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:inputType="textCapCharacters"
android:digits="0123456789=+-*^/{}.xX"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<!-- Footer Ends -->
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4"
android:layout_above="@+id/linearLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/One"
android:id="@+id/button1"
android:layout_above="@+id/button4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Two"
android:id="@+id/button2"
android:layout_alignTop="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:layout_toEndOf="@+id/button1"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Three"
android:id="@+id/button3"
android:layout_alignBottom="@+id/button2"
android:layout_toRightOf="@+id/button2"
android:layout_toEndOf="@+id/button2"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Plus"
android:id="@+id/buttonPlus"
android:layout_above="@+id/button6"
android:layout_toRightOf="@+id/button3"
android:layout_toEndOf="@+id/button3"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4"
android:layout_above="@+id/linearLayout3"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Four"
android:id="@+id/button4"
android:layout_above="@+id/button7"
android:layout_toLeftOf="@+id/button8"
android:layout_toStartOf="@+id/button8"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Five"
android:id="@+id/button5"
android:layout_above="@+id/button8"
android:layout_alignLeft="@+id/button2"
android:layout_alignStart="@+id/button2"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Six"
android:id="@+id/button6"
android:layout_alignTop="@+id/button5"
android:layout_toRightOf="@+id/button5"
android:layout_toEndOf="@+id/button5"
android:background="#64010001"
android:textColor="#FFFFFCFC"
android:singleLine="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Minus"
android:id="@+id/buttonMinus"
android:layout_above="@+id/button9"
android:layout_toRightOf="@+id/button6"
android:layout_toEndOf="@+id/button6"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/linearLayout4"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Seven"
android:id="@+id/button7"
android:layout_above="@+id/button0"
android:layout_toLeftOf="@+id/button8"
android:layout_toStartOf="@+id/button8"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Eight"
android:id="@+id/button8"
android:layout_alignBottom="@+id/button7"
android:layout_alignLeft="@+id/button5"
android:layout_alignStart="@+id/button5"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Nine"
android:id="@+id/button9"
android:layout_alignTop="@+id/button8"
android:layout_toRightOf="@+id/button8"
android:layout_toEndOf="@+id/button8"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Multiply"
android:id="@+id/buttonMul"
android:layout_alignBottom="@+id/button9"
android:layout_toRightOf="@+id/button9"
android:layout_toEndOf="@+id/button9"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="4"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Dot"
android:id="@+id/buttonDot"
android:background="#64010001"
android:textColor="#FFFFFCFC"
android:layout_below="@+id/button7"
android:layout_toLeftOf="@+id/button8"
android:layout_toStartOf="@+id/button8" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Zero"
android:id="@+id/button0"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/button7"
android:layout_alignRight="@+id/button8"
android:layout_alignEnd="@+id/button8"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Equal"
android:id="@+id/buttonEqual"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/button0"
android:layout_toEndOf="@+id/button0" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Divide"
android:id="@+id/buttonDiv"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/button9"
android:layout_toEndOf="@+id/button9"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/linearLayout1"
android:orientation="horizontal"
android:weightSum="4">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/VariableX"
android:layout_weight="1"
android:id="@+id/buttonVarX"
android:layout_above="@+id/button1"
android:layout_toLeftOf="@+id/button2"
android:layout_toStartOf="@+id/button2"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/OpenBraces"
android:id="@+id/buttonOB"
android:layout_above="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:layout_toEndOf="@+id/button1"
android:background="#c6010101"
android:textColor="#FFFFFCFC" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/CloseBraces"
android:id="@+id/buttonCB"
android:layout_above="@+id/button2"
android:layout_toRightOf="@+id/button2"
android:layout_alignRight="@+id/button3"
android:layout_alignEnd="@+id/button3"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Power"
android:id="@+id/buttonPow"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC"
android:layout_above="@+id/buttonPlus"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</LinearLayout>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="@+id/buttonBS"
android:src="@android:drawable/ic_media_rew"
android:background="#c6010101"
android:contentDescription="@string/Back"
android:layout_above="@+id/linearLayout0"
android:layout_alignRight="@+id/webView"
android:layout_alignEnd="@+id/webView" />
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/webView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/editText"
android:layout_alignRight="@+id/linearLayout1"
android:layout_alignEnd="@+id/linearLayout1"
android:layout_above="@+id/buttonBS" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/buttonSolution"
android:id="@+id/buttonSol"
android:layout_above="@+id/linearLayout0"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
then it android:background not only fill the button area but also fills the outer area of the button. At this area the button click is not working because it is not part of the Button but it looks like as it is part of the button as you can see in this pic
The empty space out side of the button is shown in this picture. i want to show it with this shape with white text and black button color.
i have also try to use android:backgroundTint="#c6010101" it shows in android as i want but it does not work on mobile.
it can be resolved by giving the shape. we can do it by using the select
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_1_selected"
android:state_pressed="true"/>
<!-- focused state -->
<item android:drawable="@drawable/button_1_focused"
android:state_focused="true"/>
<!-- default state -->
<item android:drawable="@drawable/button_1_normal"/>
</selector>
write this code and save with extension .xml (btn_black.xml) in drawable folder of E:My-Applicationappsrcmainresdrawable
and in your button xml code add this code
also write the code of focused, normal and selected in xml and save in the same folder(drawable) with the the name as you have given in the selector code. in this code file name will be
button_1_focused.xml
button_1_normal.xml
button_1_selected.xml
button_1_normal.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/button_1_normal_background"/>
<corners android:radius="10dip"/>
</shape>
similer for other . Also see this side http://www.codeproject.com/Articles/1006843/An-Efficient-Way-to-Make-Button-Color-Change-on-An
链接地址: http://www.djcxy.com/p/31470.html