我很抱歉,因为我在写了很多类似的问题(我猜你知道)已经存在,但我需要你的帮助。我尝试了其他帖子中描述的不同方法,但没有一个适合我。我是Android新手,我有一个简单的“Hello World!”应用程序。我定制了一个自定义材质设计主题和一个按钮,也是定制的。我试图使用“onClick”函数来显示一个TextView单击按钮时,但我不知道该怎么做。这里是我的相对布局:如何使用onClick函数使按钮显示文本视图
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="@+id/helloworld1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:text="@string/hello_world"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/press_here"
android:textColor="@color/White"
android:background="@color/Red"
android:translationY="40dp"/>
这里是我的MainActivity.java:
package com.giuskiller.material;
import android.app.*;
import android.os.*;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
* “我尝试使用 ”的onClick“ 功能” * ...这里是你的代码的功能? – codeMagic
我删除了它,因为它不起作用 –
您仍然应该包含它,以便其他人可以向您显示您出错的位置。否则,我们不知道。 – codeMagic