Android ImageButton图标未显示

Android ImageButton图标未显示,android,xamarin,imagebutton,Android,Xamarin,Imagebutton,我想有圆角和背景颜色的ImageButton,在按下状态下会发生变化。问题是我根本看不到我的图标 这是我的代码: <ImageButton android:layout_width="60dp" android:layout_height="60dp" android:layout_marginTop="85dp" android:layout_gravity="right" android:layout_marginRight=

我想有圆角和背景颜色的ImageButton,在按下状态下会发生变化。问题是我根本看不到我的图标

这是我的代码:

<ImageButton
      android:layout_width="60dp"
      android:layout_height="60dp"
      android:layout_marginTop="85dp"
      android:layout_gravity="right"
      android:layout_marginRight="20dp"
      android:background="@drawable/imgButtonStyle"
      android:src="@drawable/myIcon"
      android:id="@+id/imgButton"/>
我误解了什么吗

感谢您的帮助

解决方案

此问题的解决方案是将图标的大小调整为ImageButton的大小。我的图标相当大(和按钮的大小相比),所以我什么都看不见


谢谢大家的帮助。最后,这是一个微不足道的问题。

主要活动

package com.notificationdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.demo_layout);




    }

}
demo_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <ImageButton
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_marginTop="85dp"
        android:layout_gravity="right"
        android:layout_marginRight="20dp"
        android:background="@drawable/temp_selector"
        android:src="@mipmap/ic_launcher"
        android:id="@+id/imgButton"/>

</LinearLayout>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid android:color="#9F1D1F" />
            <corners android:bottomRightRadius="30dp"
                android:bottomLeftRadius="30dp"
                android:topRightRadius="30dp"
                android:topLeftRadius="30dp"/>
        </shape>
    </item>
    <item android:state_pressed="false">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid android:color="#0578AF" />
            <corners android:bottomRightRadius="30dp"
                android:bottomLeftRadius="30dp"
                android:topRightRadius="30dp"
                android:topLeftRadius="30dp"/>
        </shape>
    </item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageButton
        android:id="@+id/imgButton"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_gravity="right"
        android:layout_marginRight="20dp"
        android:layout_marginTop="85dp"
        android:background="@drawable/imgbuttonstyle"
        android:src="@drawable/v_light" />
</LinearLayout >

temp_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <ImageButton
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_marginTop="85dp"
        android:layout_gravity="right"
        android:layout_marginRight="20dp"
        android:background="@drawable/temp_selector"
        android:src="@mipmap/ic_launcher"
        android:id="@+id/imgButton"/>

</LinearLayout>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid android:color="#9F1D1F" />
            <corners android:bottomRightRadius="30dp"
                android:bottomLeftRadius="30dp"
                android:topRightRadius="30dp"
                android:topLeftRadius="30dp"/>
        </shape>
    </item>
    <item android:state_pressed="false">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid android:color="#0578AF" />
            <corners android:bottomRightRadius="30dp"
                android:bottomLeftRadius="30dp"
                android:topRightRadius="30dp"
                android:topLeftRadius="30dp"/>
        </shape>
    </item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageButton
        android:id="@+id/imgButton"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_gravity="right"
        android:layout_marginRight="20dp"
        android:layout_marginTop="85dp"
        android:background="@drawable/imgbuttonstyle"
        android:src="@drawable/v_light" />
</LinearLayout >

这里是我附加的屏幕

检查这个

Main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <ImageButton
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_marginTop="85dp"
        android:layout_gravity="right"
        android:layout_marginRight="20dp"
        android:background="@drawable/temp_selector"
        android:src="@mipmap/ic_launcher"
        android:id="@+id/imgButton"/>

</LinearLayout>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid android:color="#9F1D1F" />
            <corners android:bottomRightRadius="30dp"
                android:bottomLeftRadius="30dp"
                android:topRightRadius="30dp"
                android:topLeftRadius="30dp"/>
        </shape>
    </item>
    <item android:state_pressed="false">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <solid android:color="#0578AF" />
            <corners android:bottomRightRadius="30dp"
                android:bottomLeftRadius="30dp"
                android:topRightRadius="30dp"
                android:topLeftRadius="30dp"/>
        </shape>
    </item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageButton
        android:id="@+id/imgButton"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_gravity="right"
        android:layout_marginRight="20dp"
        android:layout_marginTop="85dp"
        android:background="@drawable/imgbuttonstyle"
        android:src="@drawable/v_light" />
</LinearLayout >

imgButtonStyle.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="true" >
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
               android:shape="rectangle" >
            <solid android:color="#9F1D1F" />
            <corners android:bottomLeftRadius="30dp"
                     android:bottomRightRadius="30dp"
                     android:topLeftRadius="30dp"
                     android:topRightRadius="30dp" />
        </shape >
    </item >
    <item android:state_pressed="false" >
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
               android:shape="rectangle" >
            <solid android:color="#0578AF" />
            <corners android:bottomLeftRadius="30dp"
                     android:bottomRightRadius="30dp"
                     android:topLeftRadius="30dp"
                     android:topRightRadius="30dp" />
        </shape >
    </item >
</selector >


发布完整的xmlRemove
xmlns:android=”http://schemas.android.com/apk/res/android“
来自
tag@PriyankPatel它也不工作。如果不需要使用ImageButton。您可以使用ImageView并将其包装在RelativeLayout中。代码中似乎没有错误。我认为您正在将图像可绘制放置在不同dpi的文件夹中,但缺少一个文件夹。请尝试将图像放置在可绘制文件夹中。据我所知,与我的代码相比,您没有做任何更改。我没有做任何更改,只是添加了线性布局,但它显示了带有样式的按钮。您可以更精确一些吗?我不明白你的意思。把你的图标放在drawable文件夹里,然后试试。它会工作的。事实上,我试过你的代码,做了一个演示项目,它会工作得很好,不会出现任何图标错误。我会把ic_启动器放进去temporary@PeMaCN我也附上了图片