Android studio 如何使用文本视图、按钮和祝酒词创建活动?
我是基本的。在android studio中,我想开始一个基础项目 我想在纯文本视图中键入“任意单词”。 只有当我点击一个按钮,我们才能看到这个词作为祝酒词。 这个案例我需要:一个平面文本视图、一个按钮和一个祝酒词。 我该怎么做 感谢您的回复。Android studio 如何使用文本视图、按钮和祝酒词创建活动?,android-studio,Android Studio,我是基本的。在android studio中,我想开始一个基础项目 我想在纯文本视图中键入“任意单词”。 只有当我点击一个按钮,我们才能看到这个词作为祝酒词。 这个案例我需要:一个平面文本视图、一个按钮和一个祝酒词。 我该怎么做 感谢您的回复。 在xml文件中,您需要为TextView和button设置一个id 在您的活动中: //扣上按钮 按钮=(按钮)findViewById(R.id.but); txt1=(text1)findViewById(R.id.text1); txt2=(tex
}
您的XML代码应该是这样的。请注意EditText和TextView的id,它们对于提取字符串和分别设置字符串至关重要。
还要注意按钮上的“onClick”函数,它是调用MainActivity(Java类)中同名方法所必需的。 再次注意分别使用“id”、“enterText”和“newText”声明EditText对象
希望这能有所帮助。请问,我想用按钮形状键入一个单词是什么意思?什么?我不明白你想说什么。
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/enterText"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="changeText"
android:text="Show Now"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/newText"/>
</LinearLayout>
public void changeText(View view){
EditText editText = findViewById(R.id.enterText);
String res = editText.getText().toString();
TextView textView = findViewById(R.id.newText);
textView.setText(res);
}