안드로이드 이미지 버튼 텍스트 - andeuloideu imiji beoteun tegseuteu

나는 ImageButton있고 그것에 텍스트와 이미지를 보여주고 싶습니다. 그러나 에뮬레이터를 시도하면 :

Show
    <ImageButton
        android:text="OK"
        android:id="@+id/buttonok"
        android:src="@drawable/buttonok"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    텍스트는 없지만 이미지를 얻습니다. 텍스트를 어떻게 표시 할 수 있습니까? 도와주세요!



    답변

    사용할 수 없으므로 android:text일반 버튼을 사용하고 복합 드로어 블 중 하나를 사용하는 것이 좋습니다. 예를 들어 :

    <Button
        android:id="@+id/buttonok"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/buttonok"
        android:text="OK"/>

    당신은 당신이 원하는 목적지까지 사용하여 당김을 넣을 수 있습니다 : drawableTop, drawableBottom, drawableLeft또는 drawableRight.

    최신 정보

    버튼의 경우도 이것도 꽤 잘 작동합니다. 퍼팅 android:background은 괜찮습니다!

    <Button
        android:id="@+id/fragment_left_menu_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_bg"
        android:text="@string/login_string" />

    방금이 문제가 있었고 완벽하게 작동하고 있습니다.


    답변

    ImageButton실제로 원하는 경우 캡션을 기술적으로 사용할 수 있습니다. 를 사용하여 TextView오버 오버하십시오 . 클릭 할 수 없도록하십시오 .ImageButtonFrameLayoutTextview

    예:

    <FrameLayout>
        <ImageButton
            android:id="@+id/button_x"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@null"
            android:scaleType="fitXY"
            android:src="@drawable/button_graphic" >
        </ImageButton>
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:clickable="false"
            android:text="TEST TEST" >
        </TextView>
    </FrameLayout>


    답변

    얘들 아 설정 및 로그 아웃 버튼을 개발해야하며 아래 코드를 사용했습니다.

    안드로이드 이미지 버튼 텍스트 - andeuloideu imiji beoteun tegseuteu

        <Button
            android:id="@+id/imageViewLogout"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/size_30dp"
            android:layout_alignParentLeft="true"
            android:text="Settings"
            android:drawablePadding="10dp"
            android:background="@android:color/transparent"
            android:layout_alignParentBottom="true"
            android:drawableTop="@drawable/logout" />


    답변

    실제로, android:text인수가 허용되지 ImageButton
    않지만 지정된 배경 (Android 기본값이 아님)으로 버튼을 얻으려고하면 android:backgroundxml 속성을 사용 하거나 클래스에서 선언하십시오..setBackground();


    답변

    LinearLayout대신 Button내 앱에서 사용한 배열을 사용하는 대신 사용할 수 있습니다.

     <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:background="@color/mainColor"
            android:orientation="horizontal"
            android:padding="10dp">
    
            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:background="@drawable/ic_cv"
                android:textColor="@color/offBack"
                android:textSize="20dp" />
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:text="@string/cartyCv"
                android:textColor="@color/offBack"
                android:textSize="25dp" />
    
        </LinearLayout>


    답변

    대신 일반 Button및 android : drawableTop 속성 (또는 왼쪽, 오른쪽, 아래쪽)을 사용할 수 있습니다.


    답변

    가장 좋은 방법은:

    <Button
    android:text="OK"
    android:id="@+id/buttonok"
    android:background="@drawable/buttonok"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>