安卓如何使用Java开发应用程序来引用布局对象(XML)?
例如,这是我的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<安卓.support.constraint.ConstraintLayout
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:app="http://schemas.安卓.com/apk/res-auto"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
安卓:id="@+id/textView"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_marginTop="26dp"
安卓:text="Wat wil je gemiddeld komen te staan?"
安卓:textAlignment="center"
安卓:textSize="30sp"
安卓:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
安卓:id="@+id/editText1"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:gravity="center"
安卓:hint="Typ het hier in"
安卓:inputType="numberDecimal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<Button
安卓:id="@+id/button"
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_marginTop="20dp"
安卓:gravity="center"
安卓:text="Volgende"
安卓:background="#ff0000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText1" />
这是我迄今为止的Java代码:
package com.firstapp.myapplication;
import 安卓.os.Bundle;
import 安卓.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public static void main(String[] args) {
}
}
假设我希望EditText的最大输入值为2位小数,那么如何在Java中引用来进行这些更改呢?所以我基本上想把逻辑添加到XML布局对象中,但我不知道如何在Java中处理它们
共 (0) 个答案