当前位置: 首页 > 知识库问答 >
问题:

材料设计文本输入布局在接触之前保持不可见

萧繁
2023-03-14

使用材料设计“com.google.android.Material:Material:1.2.1”depedency我正在创建登录屏幕。我在ConstraintLayout->LinearLayout->com.google.android.Material.TextField.TextInputLayout下使用了com.google.android.Material.TextInputLayout。当layout加载时,textfield是不可见的,如果我单击该区域,它就会显示出来。如果我删除根约束布局的背景颜色,那么文本字段是可见的,但我想要白色背景。我试过改变风格,但不起作用

activit_login.xml

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/constrant"
    android:background="@color/white"
    tools:context=".Login">

    <View
        android:id="@+id/topView"
        android:layout_width="0dp"
        android:layout_height="150dp"
        android:background="@color/colorPrimary"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/view2"
        android:layout_width="0dp"
        android:layout_height="100dp"
        android:background="@drawable/wave"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/topView" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="32dp"
        android:layout_marginEnd="32dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/cat" />

    <TextView
        android:id="@+id/txt_login"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="76dp"
        android:text="Login"
        android:textAlignment="center"
        android:textColor="#F8F7F7"
        android:textSize="36sp"
        android:textStyle="normal|bold"
        app:layout_constraintEnd_toStartOf="@+id/imageView"
        app:layout_constraintHorizontal_bias="0.363"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <LinearLayout
        android:layout_width="409dp"
        android:layout_height="479dp"
        android:orientation="vertical"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/view2">

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/outlinedTextField"
            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/username"
            app:startIconDrawable="@drawable/ic_phone_android">

            <com.google.android.material.textfield.TextInputEditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:maxLength="10" />

        </com.google.android.material.textfield.TextInputLayout>
    </LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

AndroidMenifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="get.get.get">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".Register"></activity>
        <activity android:name=".Login"  android:theme="@style/AppNoActionBar"/>
        <activity
            android:name=".Splash"
            android:theme="@style/Theme.MaterialComponents.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity" />
    </application>

</manifest>

style.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppNoActionBar" parent="Theme.MaterialComponents.NoActionBar.Bridge">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

        <item name="boxStrokeColor">@color/colorPrimary</item>
        <item name="boxStrokeWidth">2dp</item>
    </style>
</resources>

共有1个答案

邓令
2023-03-14

如果我理解正确的话,您可以使用这个答案来更改默认框的笔画颜色。

 类似资料:
  • 简单地说,我不想使用第三方库,我只想知道是否可以使用android支持库以及如何做到这一点。

  • 我正在尝试在我的项目中使用材料设计,但我没有找到一种方法来导入它。我花了很多时间在互联网和stackoverflow中尝试用户的建议,但无论我尝试什么都不起作用。 我在Mac OSX 10.10上使用Android Studio 0.8.14。使用gradle 13.2和JDK jdk1.8.0_25.JDK。从图片中可以看到,我的android SDK是最新的 这是我的卷轴 有人能帮我吗?我做错

  • 我想我可能误解了在线文档,但是有很多关于使用Android设计支持库为Android应用程序实现材料设计的文章。 我有一个最低SDK14的应用程序,我可以增加到16.我不使用协调员布局或任何东西,但对材料设计主题和Snackbar有以下依赖关系。 我想知道我是否可以删除对AppCompat的依赖,而只是使用设计支持库来实现材料设计主题,但无法找到如何获得它。还是我理解错了?

  • 如何使用材质设计将按钮放置在图中所示的位置? 这是index.html模板上的代码。 这是材质设计的css样式。 Lorem ipsum dolor sit amet,consectetur adipisicing elit,sed do eusmod tempor incidunt ut labore et dolore magna aliqua.Ut enim ad minim veniam,

  • 有人能告诉我如何开始实施Android Material Design guide中描述的垂直非线性步进控制吗 http://www.google.com/design/spec/components/steppers.html

  • 我正在使用新的谷歌设计库(com . Android . support:design:22 . 2 . 0 ),我在使用Android . support . design . widget . textinputlayout时遇到了问题。 如果我以编程方式设置它的EditText,浮动提示颜色是灰色而不是强调色。如果用户自己填充字段(EditText)或者如果他改变字段的预定义值,它就工作。

  • 错误:依赖项MyApplication.Libraries:project app上的MaterialDesign:未指定将解析为不支持作为编译依赖项的APK归档。文件:C:\adtbundle\studioworkspace\myapplication\libraries\MaterialDesign\build\outputs\apk\MaterialDesign-release-unsign

  • 这是我的材料风格 如果我从XML创建EditText(或其他组件),EditText的颜色将使用色彩控制正常 但是当我动态创建EditText时,它不会使用这些颜色。(变成黑色) 如何设置组件的样式或动态更改颜色? [更新] 自定义EditText类也可以解决此问题。