Java 为什么“文本”在customdialog打开时不显示?

Java 为什么“文本”在customdialog打开时不显示?,java,android,xml,Java,Android,Xml,我觉得自己像个白痴。我复制了这个项目。zip文件无法导入Android Studio 1.0.2。建议是将它迁移到Gradle,但我不知道怎么做。后来我找到了这样做的链接。我无法实现它。它在这混乱的底部 所以我创建了一个新项目,剪切并粘贴了3XML和1Java文件。我终于明白了 应该会显示下面的对话框,但当我运行它时,它不会显示文本的文本,这是Android自定义对话框示例。它只是显示图标;在custom.xml中指定的右侧完全没有文本。我花了几个小时的时间,显然我对Android java或x

我觉得自己像个白痴。我复制了这个项目。zip文件无法导入Android Studio 1.0.2。建议是将它迁移到Gradle,但我不知道怎么做。后来我找到了这样做的链接。我无法实现它。它在这混乱的底部

所以我创建了一个新项目,剪切并粘贴了3XML和1Java文件。我终于明白了

应该会显示下面的对话框,但当我运行它时,它不会显示文本的文本,这是Android自定义对话框示例。它只是显示图标;在custom.xml中指定的右侧完全没有文本。我花了几个小时的时间,显然我对Android java或xml或连接没有很好的掌握——我正在研究它,但我看到了我希望在java和xml中看到的,用于名为text的TextView的东西,试图解决这个问题。我现在希望你们都能帮我一把

在custom.xml文件下面列出了我徒劳尝试的内容

编辑-以下是我看到的:

这是AndroidManifest.xml:

这是main.xml

我删除了一个/>,在TextView的custom.xml中可以看到两个

我向dialogButton.setOnClickListener添加了视图,如下所示:

dialogButton.setOnClickListener(new View.OnClickListener() {
我注释掉了整个dialogButton.setOnClickListener

我删除了“toRightOf…image”这句话

我从custom.xml中删除了除名为text的TextView之外的所有对象,并从MainActivity.java中删除了连接的代码

我调试了它,文本包含了它应该显示的文本,但没有显示

都没有用

以下是gradle.build for应用程序:

我知道这对于一个经验丰富的Android程序员来说是件小事,但我就是找不到。我发现Android图形用户界面并没有什么不重要的地方

我希望没有人会觉得有义务从所有这些文件创建一个项目。我希望对于一个经验丰富的安卓程序员来说,缺失的连接是显而易见的

在尝试迁移到gradle时,我使用了在`'处找到的build.gradle文件,但它不喜欢这一行:

            classpath 'com.android.tools.build:gradle:0.5.+'


buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

我看到了你照片上的文字。对话框的背景是白色的,您将textColor指定为FFF,这就是您无法看到它的原因。更改对话框的背景或字体的颜色。

修复程序实际上依赖于Android Studio:我将选择主题的下拉列表从AppTheme更改为Base.theme.appCompat。因此,代码的工作方式与开头显示的链接相同。但是,这种臭味,花了这么多的努力来追查这个问题

然而,删除不明智的FFF文本颜色是一个更好的主意。就像我说的,我只是复制了代码

道德?如果你要设置文本颜色,你应该设置对话框的颜色

所以我做了。我将下拉主题设置回AppTheme,以表明它确实没有引起问题

以下是成功的本质:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
    android:background="#ff4b14ff">

    <TextView
        android:id="@+id/text"
...
        android:layout_toRightOf="@+id/image"
        android:layout_toEndOf="@+id/image"
        android:textColor="#FFF"/>
我又加了一句…托恩多夫。。。因为Android Studio建议这样做是为了兼容性


很高兴看到有两张赞成票支持清晰性和研究性。。。当然是自动生成的。标题。。。对话框上是否显示字符串?是。一切都很好,只是没有文字对文字。我将进行编辑以显示我看到的内容。@DSlomer64:您确定可以看到文本颜色是否为FFFFFF吗?我刚刚删除了它。我在上面。正如上面所说的,是的,这是个问题。谢谢。请将此问题标记为已回答。很乐意帮忙。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="5dp" />

    <TextView
        android:id="@+id/text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#FFF"
        android:layout_toRightOf="@+id/image"/>/>

    <Button
        android:id="@+id/dialogButtonOK"
        android:layout_width="100px"
        android:layout_height="wrap_content"
        android:text=" Ok "
        android:layout_marginTop="5dp"
        android:layout_marginRight="5dp"
        android:layout_below="@+id/image"
        />

</RelativeLayout>
dialogButton.setOnClickListener(new View.OnClickListener() {
apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.dslomer64.android"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
}
            classpath 'com.android.tools.build:gradle:0.5.+'


buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}
        classpath 'com.android.tools.build:gradle:2.2.1'
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
...
    android:background="#ff4b14ff">

    <TextView
        android:id="@+id/text"
...
        android:layout_toRightOf="@+id/image"
        android:layout_toEndOf="@+id/image"
        android:textColor="#FFF"/>