77范文网 - 专业文章范例文档资料分享平台

基于Android的背单词软件设计与实现计算机毕业论文(8)

来源:网络收集 时间:2019-03-16 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

import android.os.Bundle; import android.view.View; import android.widget.Button; import java.util.Date; public class NowRedux extends Activity implements View.OnClickListener { Button btn;

@Override

public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main);

btn=(Button)findViewById(R.id.button);btn.setOnClickListener(this);updateTime();

}

public void onClick(View view) { updateTime(); }

private void updateTime() { btn.setText(new Date().toString()); } }

The first difference is that rather than setting the content view to be a view we created in Java code, we set it to reference the XML layout (setContentView(R.layout.main)). The R.java source file will be updated when we rebuild this project to include a reference to our layout file (stored as main.xml in our project’s res/layout directory). The other difference is that we need to get our hands on our Button instance, for which we use the findViewById() call. Since we identified our button as @+id/button, we can reference the button’s identifier as R.id.button. Now, with the Button instance in hand, we can set the callback and set the label as needed. As you can see in Figure 5-1, the results look the same as with the original Now demo. 32

Figure 5-1. The NowRedux sample activity

Employing Basic Widgets Every GUI toolkit has some basic widgets: fields, labels, buttons, etc. Android’s toolkit is no different in scope, and the basic widgets will provide a good introduction as to how widgets work in Android activities. Assigning Labels The simplest widget is the label, referred to in Android as a TextView. Like in most GUI toolkits, labels are bits of text not editable directly by users. Typically, they are used to identify adjacent widgets (e.g., a ―Name:‖ label before a field where one fills in a name). In Java, you can create a label by creating a TextView instance. More commonly, 33

though, you will create labels in XML layout files by adding a TextView element to the layout, with an android:text property to set the value of the label itself. If you need to swap labels based on certain criteria, such as internationalization, you may wish to use a resource reference in the XML instead, as will be described in Chapter 9. TextView has numerous other properties of relevance for labels, such as:

? android:typeface to set the typeface to use for the label (e.g., monospace) ? android:textStyle to indicate that the typeface should be made bold (bold), italic (italic),or bold and italic (bold_italic) ? android:textColor to set the color of the label’s text, in RGB hex format (e.g., #FF0000 for red) For example, in the Basic/Label project, you will find the following layout file:

34

Button, Button, Who’s Got the Button? We’ve already seen the use of the Button widget in Chapters 4 and 5. As it turns out, Button is a subclass of TextView, so everything discussed in the preceding section in terms of formatting the face of the button still holds. Fleeting Images Android has two widgets to help you embed images in your activities: ImageView and ImageButton. As the names suggest, they are image-based analogues to TextView and Button, respectively. Each widget takes an android:src attribute (in an XML layout) to specify what picture to use. These usually reference a drawable resource, described in greater detail in the chapter on resources. You can also set the image content based on a Uri from a content provider via setImageURI().

ImageButton, a subclass of ImageView, mixes in the standard Button behaviors, for responding to clicks and whatnot.

For example, take a peek at the main.xml layout from the Basic/ImageView sample project which is found along with all other code samples at http://apress.com:

The result, just using the code-generated activity, is shown in Figure 6-2. 35

Figure 6-2. The ImageViewDemo sample application Fields of Green. Or Other Colors. Along with buttons and labels, fields are the third ―anchor‖ of most GUI toolkits. In Android, they are implemented via the EditText widget, which is a subclass of the TextView used for labels.

Along with the standard TextView properties (e.g., android:textStyle), EditText has many others that will be useful for you in constructing fields, including: ? android:autoText, to control if the field should provide automatic spelling assistance ? android:capitalize, to control if the field should automatically capitalize the first letter of entered text (e.g., first name, city) ? android:digits, to configure the field to accept only certain digits ? android:singleLine, to control if the field is for single-line input or multiple-line input (e.g., does move you to the next widget or add a newline?) Beyond those, you can configure fields to use specialized input methods, such as android:numeric for numeric-only input, android:password for shrouded password input, 36

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库基于Android的背单词软件设计与实现计算机毕业论文(8)在线全文阅读。

基于Android的背单词软件设计与实现计算机毕业论文(8).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/524666.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: