ImageButton에 텍스트를 표시하는 방법?
나는 ImageButton
있고 그것에 텍스트와 이미지를 보여주고 싶다. 그러나 에뮬레이터를 시도하면 :
<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
오버 오버하십시오 . 클릭 할 수 없도록하십시오 .ImageButton
FrameLayout
Textview
예:
<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>
실제로, android:text
인수가 허용되지 ImageButton
않지만 지정된 배경 (Android 기본값이 아님)으로 버튼을 얻으려고하면 android:background
xml 속성을 사용 하거나 클래스에서 선언하십시오..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: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" />
대신 일반 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"/>
나는 넣어이 문제를 해결 ImageButton
하고 TextView
내부에 LinearLayout
수직 방향으로. 잘 작동합니다!
<LinearLayout
android:id="@+id/linLayout"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageButton
android:id="@+id/camera_ibtn"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:background="@drawable/camera" />
<TextView
android:id="@+id/textView2"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/take_pic"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
좋은 원 예는 다음과 같습니다.
drawable/circle.xml
:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#ff87cefa"/>
<size
android:width="60dp"
android:height="60dp"/>
</shape>
그리고 xml 파일의 버튼 :
<Button
android:id="@+id/btn_send"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/circle"
android:text="OK"/>
ImageButton
가질 수 없습니다 text
(또는 적어도 android:text
속성에 나열되지 않음).
간계는 :
It looks like you need to use Button
(and look at drawableTop
or setCompoundDrawablesWithIntrinsicBounds(int,int,int,int))
.
참고URL : https://stackoverflow.com/questions/4457030/how-to-show-the-text-on-a-imagebutton
'Programming' 카테고리의 다른 글
가로 LinearLayout의 오른쪽 맞춤 버튼 (0) | 2020.07.16 |
---|---|
Android : 가로 모드 용 대체 레이아웃 XML (0) | 2020.07.16 |
C #에서 사전을 JSON 문자열로 어떻게 변환합니까? (0) | 2020.07.16 |
vim에서 창을 뒤집는 방법? (0) | 2020.07.16 |
Objective-C : 카테고리의 특성 / 인스턴스 변수 (0) | 2020.07.16 |