나는 안드로이드에서 배경색 변경으로 둥근 모서리 단추를 할 필요가있다.안드로이드에 배경색이있는 둥근 모서리 단추
어떻게 할 수 있습니까?
예제 링크/코드를 보내 주시면 감사하겠습니다.
나는 안드로이드에서 배경색 변경으로 둥근 모서리 단추를 할 필요가있다.안드로이드에 배경색이있는 둥근 모서리 단추
어떻게 할 수 있습니까?
예제 링크/코드를 보내 주시면 감사하겠습니다.
Android 모양 도형을 사용하고 싶습니다. http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
드로어 블/사진 cool_button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="@dimen/corner_radius" />
<gradient
android:angle="270"
android:startColor="@color/almost_white"
android:endColor="@color/somewhat_gray"
android:type="linear" />
</shape>
그런 다음 당신이 그 모양 드로어 블에서 "선택"당김을 만들어야 할 것입니다. 이렇게하면 버튼을 상태에 따라 다르게 표시 할 수 있습니다. IE : 등 http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
드로어 블/사진 cool_button.xml,
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/cool_inner_press_bottom" />
<item android:state_focused="true" android:state_enabled="true"
android:state_window_focused="true"
android:drawable="@drawable/cool_inner_focus_bottom" />
<item
android:drawable="@drawable/cool_button_background" />
</selector>
보너스를 누르면 초점을 맞추고 : 당신은 할 수 당신이 그 (것)들을 프로그램 전반에 걸쳐 일관성을 가질 수 있도록 버튼의 스타일을 만들려고합니다. 이 단계를 생략하고 버튼의 android : background = "@ drawable/cool_button"을 설정할 수 있습니다.
값/styles.xml
마지막<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyCoolButton">
<item name="android:background">@drawable/cool_button_background</item>
</style>
</resources>
버튼!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/appwidget_bg">
<Button
android:id="@+id/btnAction"
android:layout_width="wrap_content"
android:layout_weight="wrap_content"
style="@style/CoolButton"
/>
</LinearLayout>
오기 PorterDuff 및가
에게 가import android.graphics.PorterDuff.Mode;
Button btn = (Button) findViewById(R.id.myButton);
btn.getBackground().setColorFilter(Color.GRAY, Mode.MULTIPLY);
= "@ 스타일/CoolButton는"스타일 변경되어야
그것이있을 것이다 다음 setColorFilter()를 사용하여 독자는 코드 대신 설명을 남기면 도움이됩니다. –
작은 보정 스타일 = "@ 스타일/MyCoolButton" – user2582651