2011-05-12 3 views
1

매우 간단한 Android 애플리케이션을 작성 중입니다. 그렇게함으로써 Droid X 응용 프로그램 선택기 화면에있는 버튼 UI 요소를 에뮬레이트하는 것이 매우 어렵다는 것을 발견했습니다. 익숙하지 않은 사람들을 위해, 그들은 그 아래에 흰색 텍스트가있는 아이콘입니다. 텍스트 뒤에 검정색 둥근 사각형이 있으며 버튼을 클릭하면 아이콘 아래의 배경과 텍스트가 빨간색으로 바뀝니다.Android 개발 - 맞춤 검색 버튼 모양/동작

내 현재 솔루션에는 StateListDrawables가 포함되지만 둥근 사각형은 고정 폭을 가지며 모든 단추 아이콘으로 편집해야합니다. 현지화는 궁극적 인 목표이므로 내 솔루션은 기껏해야 일시적입니다. 나는이 일을하는 어리석은 방법이 없다고 생각 하나?

답변

0

나는 이것을 시도하지 않았고, 당신이 말하는 버튼을 본 적이 없다. 그러나 그 과정은 비슷한 것이어야합니다.

먼저 드로어 블 (실제 배경 이미지)을 만듭니다. 하나는 빨간색 배경과 하나는 투명합니다. 귀하의 당김 XML은 다음과 같이 보일 것입니다 :

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/btn_bg_red"/> 
    <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/btn_bg_red"/> 
    <item android:state_focused="true" android:drawable="@drawable/btn_bg_pressed"/> 
    <item android:state_focused="false" android:state_pressed="false" android:drawable="@android:color/transparent"/> 
</selector> 

이 그런 다음 버튼 자체가 이와 유사한 선언 할 수 있습니다 :

<Button android:id="@+id/droid_x_btn" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:text="Droid Does" 
       android:drawableTop="@drawable/btn_icon" <!-- this is for the icon on top --> 
       android:background="@drawable/ic_droid_x_button" <!-- The name of the above file without extension --> 
       android:textColor="@color/white" /> 

희망이 도움이!

+0

흠, 그게 내가 가진 것과 거의 똑같아.하지만 네가 더 우아 해. 텍스트 뒤에있는 검정색 막대는 조정할 수없는 경우에도 솔루션으로 작동 할 것입니다. 대단히 감사합니다. :) – Joshua