java - 图像按钮未在 Android 模拟器中显示

标签 java android

我遇到了一个无法找到解决方案的问题。我正在通过 Android SDK 创建一个图像按钮,尽管它显示在预览窗口中,但它不会显示在 Nexus 6 模拟器中。图片附在这里 enter image description here

xml文件的代码是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp"
    tools:context=".ViewActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:textSize="@dimen/activity_bold_textsize"
    />


    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:src="@tools:sample/avatars" />

    <CheckBox
        android:id="@+id/checkBox"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/rememberMe" />

    <RadioGroup
        android:id="@+id/radio_g1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <RadioButton
            android:id="@+id/rad1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/rad1"/>
        <RadioButton
            android:id="@+id/rad2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/rad2"
            />
    </RadioGroup>

    <ToggleButton
        android:id="@+id/toggleButton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/togb1" />

    <Switch
        android:id="@+id/switch1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/Switch" />

</LinearLayout>

最佳答案

你不知道toolsandroid之间的区别。 tools:src="@tools:sample/avatars" 仅在 IDE 预览中显示。 改成 android:src="@tools:sample/avatars"

查看文档:https://developer.android.com/studio/write/tool-attributes

关于java - 图像按钮未在 Android 模拟器中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53643982/

相关文章:

java - H2O : NullPointerException error while building ensemble model using deep learning grid

java - 按代码排序

android - 在 Android 上计算测验的分数

java - 无法解析符号 'FragmentCompat' - Camera2VideoJava - 目标为 API 29

android - 我可以为 ACTION_MEDIA_SCANNER_SCAN_FILE Intent 使用什么权限?

java - 从 java 调用编译的 C++ exe 文件不起作用

java - Android:设置默认软键盘

java - 关于 CodeName One 和 Path Java Runtime 的问题

android - 未能释放 208019456 on/data;最终可用空间 141062144 :

android - DeviceInfo native 模块未正确安装在 React Native 中