【发布时间】:2016-05-27 23:21:49
【问题描述】:
我真的很抱歉,因为我写这篇文章是在很多(我猜你知道)已经存在的类似问题之后写的,但我需要你的帮助。我尝试了其他帖子中描述的不同方法,但没有一个对我有用。我是 Android 开发的新手,我有一个简单的“Hello World!”应用程序。我使用自定义材料设计主题和按钮对其进行了自定义,也是自定义的。我试图使用“onClick”功能在单击按钮时显示 TextView,但我不知道该怎么做。这是我的相对布局:
<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”函数“...你的代码中的那个函数在哪里?
-
我已经删除它,因为它不起作用
-
您仍然应该包含它,以便其他人可以告诉您您哪里出错了。否则,我们不知道。
-
明白,抱歉。下次我会写所有的。