2013-07-10 1 views
5

main.xml의 Android 버튼에 테두리를 지정할 수 있습니까? [p.s. '분리 된 XML 파일 함유 스트로크 태그'없이하지만 용액 와 '영상'용액] 동적 프로그래밍의 '여기안드로이드 버튼에서 테두리를 지정할 수 있습니까?

<Button 
    android:background="#FFFFFF" 
    android:layout_width="0dp" 
    android:layout_height="fill_parent" 
    android:text="Player 3" 
    android:layout_x="0px" 
    android:layout_y="0px" 
    android:id="@+id/p3" 
    android:layout_weight="1" 

/> 

I가 변화하고 않고 버튼도 정의 원본 파일 배경은 동적이지만 문제는 테두리가없는 2 개의 버튼입니다.

+0

당신은 보라, 다른 버튼 상태에 대한 자신의 선택의 테두리 사용자 정의 버튼을 만들 모양 선택기 XML을 사용할 수 있습니다 [ 다른 색상의 표준 안드로이드 버튼] (http://stackoverflow.com/q/1521640/593709) –

+0

레이아웃 xmls는 그래픽 사양이 아닌 레이아웃 용입니다 – njzk2

+0

@AdilSoomro, kindof hopi 그 대답을 놓친 분이 계시 리라. 나는 셰이프 선택기 접근 방식으로 가야 할 수도 있습니다. – Nyx

답변

7

overdraw을 야기하고 불필요한 뷰를 추가하기 때문에이 그것을 할 수있는 권장 방법이 아니다, Gunaseelan has the proper method.


속성으로 테두리 개념이 없습니다. 허용 된 방법은 View의 배경으로 별도의 드로어 블을 사용하는 것입니다 (언급 한대로 stroke을 사용하고 @gunaseelan이 쓴 것처럼).

다른 (권장하지 않음) 방법은 LinearLayout 같은 다른 View에서 Button도 외부 View에 캡슐화 View 및 패딩에 원하는 테두리 색상의 배경 색상을 설정 둘러싸입니다.

<LinearLayout 
    android:layout_height="wrap_content" 
    android:layout_width="match_parent" 
    android:background="#342334" 
    android:padding="5dp" 
    > 
    <Button 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:text="whatwhaaat" 
     /> 
</LinearLayout> 

패딩의 값은 테두리의 두께를 나타냅니다. 이 방법은 레이아웃에 View이 추가로 추가되고 오버 드로우 레이어가 추가되어 (이 경우 LinearLayout 다음에 그 위에 Button이 그려집니다) 권장되지 않습니다. 추가 정보를

+0

글쎄, 나는 내가 잃어버린 총이있을 거라는 희망을 품고 있었다. 대답은 유 – Nyx

34

봅니다

my_shape.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

    <corners 
     android:bottomLeftRadius="7dp" 
     android:bottomRightRadius="7dp" 
     android:radius="0.1dp" 
     android:topLeftRadius="7dp" 
     android:topRightRadius="7dp" /> 

    <solid android:color="#FFFFFF" /> 

    <stroke 
     android:width="1dp" 
     android:color="#E8E6E7" /> 

</shape> 

그리고 버튼

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/my_shape" 
    android:text="Button" /> 

스크린 샷

enter image description here

나는 t을 희망 모양 ​​사용 그분이 당신을 도울 것입니다.

+0

안녕하세요, 나는이 바로 thing.but를 피하려고 애 쓰고 있습니다. – Nyx

+1

안녕하세요. 귀하의 코드를 사용했지만 변경 사항이 내 버튼에 반영되지 않았습니다. 도울 수 있니? –

+0

AndroidStudio는 기본적으로'shapes'가 아닌'selector '를 생성합니다. –

0

enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" > 

<gradient 
    android:angle="270" 
    android:endColor="#E8f2fe" 
    android:startColor="E8f2fe" /> 

<corners android:radius="3dp" /> 

<stroke 
    android:width="2px" 
    android:color="#486e9d" /> 

http://androiddhina.blogspot.in/2015/09/border-color-on-android-button.html

관련 문제