标签:控件 tv app 视图 result 触控 import android 文本
textAllCaps属性 & onClick属性
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="5dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="下面的按钮英文默认大写" android:textColor="@color/black" android:textSize="17sp" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World" android:textColor="@color/black" android:textSize="17sp" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="下面的按钮英文保持原状" android:textColor="@color/black" android:textSize="17sp" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello World" android:textAllCaps="false" android:textColor="@color/black" android:textSize="17sp" /> <Button android:id="@+id/btn_click_xml" android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="doClick" android:text="直接指定点击方法" android:textColor="#000000" android:textSize="17sp" /> <TextView android:id="@+id/tv_result" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这里查看按钮的点击结果" android:textColor="#000000" android:textSize="17sp" /> </LinearLayout>
package com.example.myapplication; import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } // activity_button_style.xml中给btn_click_xml指定了点击方法doClick public void doClick(View view) { TextView tv_result = findViewById(R.id.tv_result); // 获取名叫tv_result的文本视图 tv_result.setText("您点击了此按钮"); // 设置文本视图的文本内容 } }
===========================================================
123
标签:控件,tv,app,视图,result,触控,import,android,文本 来源: https://www.cnblogs.com/xiaobaibailongma/p/16437515.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。