我是android移动开发和java的新手。想知道是否有人可以帮助我解决我的问题。
现在,我正在制作我的Android应用程序的XML文件,并希望它具有如下所示的内容。
可以在不具备Java深入知识的情况下在XML文件中进行制作吗?我只想在EditText
属性中使用固定文本。在我的第一个应用程序中使用LinearLayout
。我感谢任何帮助。
使用API 28进行测试。
是,有默认布局TextInputLayout
和TextInputEditText
。这里的文档:https://developer.android.com/reference/android/support/design/widget/TextInputLayouthttps://material.io/develop/android/components/text-input-layout/
这称为TextInputLayout。读取here。演示示例here
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="true">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username" />
</android.support.design.widget.TextInputLayout>
您正在寻找TextInputLayout
组件:
TextInputLayout
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
app:boxBackgroundColor="@color/white"
app:boxStrokeColor="@color/text_input_layout_stroke_color"
app:counterMaxLength="15"
app:counterEnabled="true"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>