8种机械键盘轴体对比

本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?

Toast为应用操作提供了一种简单的反馈机制,它是一个小型的弹出窗口……A toast provides simple feedback about an operation in a small popup. It only fills the amount of space required for the message and the current activity remains visible and interactive. For example, navigating away from an email before you send it triggers a “Draft saved” toast to let you know that you can continue editing later. Toasts automatically disappear after a timeout.

Toast为应用操作提供了一种简单的反馈机制,它是一个小型的弹出窗口,只占用足够其显示消息内容的空间,而不影响当前activity的可见与交互。例如,它会在你退出未发送的邮件时,触发一条内容为”draft saved”的toast提示你能稍后继续编辑这条邮件。toast会自动在超时后消失。

If user response to a status message is required, consider instead using a Notification.

如果需要用户回馈一个状态消息,可以考虑使用notification。

The Basics基本用法First, instantiate a Toast object with one of the makeText() methods. This method takes three parameters: the application Context, the text message, and the duration for the toast. It returns a properly initialized Toast object. You can display the toast notification with show(), as shown in the following example:

首先,你需要用maketext()方法来实例化一个toast对象,这个方法有三个参数:应用的context,需要显示的文本消息,和需要显示的时间。它的返回值是一个实例化的toast对象。用show()方法来显示。如下所示:

Context context = getApplicationContext();

CharSequence text = "Hello toast!";

int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration);

toast.show();This example demonstrates everything you need for most toast notifications. You should rarely need anything else. You may, however, want to position the toast differently or even use your own layout instead of a simple text message. The following sections describe how you can do these things.

You can also chain your methods and avoid holding on to the Toast object, like this:

这个示例展示了绝大多数toast所需要的一切,你几乎不需要其他的了。然后,你或许想指定toast需要显示的位置,或者自定义toast的布局样式,接下来的部分将描述如何使用它们。

你也可以链接这些方法来避免在内存里保留一个toast对象:

Toast.makeText(context, text, duration).show();

Positioning your Toast 指定toast的位置A standard toast notification appears near the bottom of the screen, centered horizontally. You can change this position with the setGravity(int, int, int) method. This accepts three parameters: a Gravity constant, an x-position offset, and a y-position offset.

For example, if you decide that the toast should appear in the top-left corner, you can set the gravity like this:

一个标准的toast出现在靠近屏幕下方垂直居中的位置。你可以使用setGravity(int, int, int)方法改变他的位置,这个方法有3个参数。一个gravity常量,一个x轴偏移量,和一个y轴偏移量。

例如,如果你想让一个toast出现在屏幕的右上角。你可以这么设置参数:

toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);If you want to nudge the position to the right, increase the value of the second parameter. To nudge it down, increase the value of the last parameter.

如果你想向右移动位置,增加第二个参数的值;向下移动位置,增加第三个参数的值

Creating a Custom Toast View 创建一个自定义的Toast视图If a simple text message isn’t enough, you can create a customized layout for your toast notification. To create a custom layout, define a View layout, in XML or in your application code, and pass the root View object to the setView(View) method.

For example, you can create the layout for the toast visible in the screenshot to the right with the following XML (saved as toast_layout.xml):

如果一个简单的文本消息无法满足需求。你可以为你的toast指定一个布局。创建一个自定义布局,你需要定义一个xml布局文件。并且调用setView(View)方法。将根节点view当做参数传递给它。

例如,你可以用下面的代码为toast创建一个布局文件(保存为toast_layout.xml):

android:id="@+id/toast_layout_root"

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:padding="8dp"

android:background="#DAAA"

>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginRight="8dp"

/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#FFF"

/>

Notice that the ID of the LinearLayout element is “toast_layout_root”. You must use this ID to inflate the layout from the XML, as shown here:

注意这个LinearLayout元素的ID是“toast_layout_root”.你需要使用这个ID去膨胀这个布局,如下所示:

LayoutInflater inflater = getLayoutInflater();

View layout = inflater.inflate(R.layout.custom_toast,

(ViewGroup) findViewById(R.id.toast_layout_root));

TextView text = (TextView) layout.findViewById(R.id.text);

text.setText("This is a custom toast");

Toast toast = new Toast(getApplicationContext());

toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);

toast.setDuration(Toast.LENGTH_LONG);

toast.setView(layout);

toast.show();First, retrieve the LayoutInflater with getLayoutInflater() (or getSystemService()), and then inflate the layout from XML using inflate(int, ViewGroup). The first parameter is the layout resource ID and the second is the root View. You can use this inflated layout to find more View objects in the layout, so now capture and define the content for the ImageView and TextView elements. Finally, create a new Toast with Toast(Context) and set some properties of the toast, such as the gravity and duration. Then call setView(View) and pass it the inflated layout. You can now display the toast with your custom layout by calling show().

首先,调用getLayoutInflater()或者getSystemService()方法获得LayoutInflater对象,然后用inflate(int, ViewGroup)方法膨胀这个布局,第一个参数是需要膨胀的的XML布局ID,第二个参数是父视图。你可以得到这个膨胀过的layout里的其他视图对象。现在,得到并设置ImageView和TextView的内容。最后,用构造方法Toast(Context)创建一个toast对象,并且设置一些所需的属性例如位置,时长,然后调用setView(View)方法并将膨胀后的layout当做参数传递给它。现在你可以调用show()方法来显示你自定义的toast了Note: Do not use the public constructor for a Toast unless you are going to define the layout with setView(View). If you do not have a custom layout to use, you must use makeText(Context, int, int) to create the Toast.

注意:除非你打算用setView(View)方法来来定义Toast的布局,否则请勿使用toast的公共构造方法创建一个Toast。如果你没有自定义Toast的布局,请务必使用makeText(Context, int, int)方法来创建一个Toast。

android guide 中文,Android API Guide:Toast 中文翻译相关推荐

  1. android官方文档翻译,Android API Guide:Search 中文翻译

    8种机械键盘轴体对比 本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选? 搜索,是安卓的一个核心功能.用户可以搜索他们所有能获得的数据,无论这些内容在设备上或者在网络上. Search Over ...

  2. Android SDK 2.1 - Dev Guide - Best Practives - UI Guidelines - Activity and Task Design - 中文/Chinese

    转自:http://blog.csdn.net/sirdonker/article/details/5647625 Activity 和 task 的设计摘要 Activity 是 Android 应 ...

  3. Android SDK包功能介绍,中文开发API

    Android 包索引 这些是API包. 查看全部 API classes . android 包含平台中包含的应用程序使用的资源类,并定义系统功能的应用程序权限. android.accessibi ...

  4. Android的TextView在显示文字的时候,如果有段中文有英文,有中文,有中文标点符号,你会发现,当要换行的时候遇到中文标点, 这一行就会空出很多空格出来...

    一.问题描述: Android的TextView在显示文字的时候,如果有段中文有英文,有中文,有中文标点符号,你会发现,当要换行的时候遇到中文标点, 这一行就会空出很多空格出来.原因是: 1) Tex ...

  5. android 语音播报中文,android 语音播报(通过手说tts 实现中文语音播报)

    手说TTS介绍: 手说TTS,是Android平台下的中文语音引擎,提供了中文文本到语音的转换. 使用手说TTS进行中文文本的朗读,包括中文简繁体.阿拉伯数字.英文字母及一些符号的混读.并且处理了中文 ...

  6. Android 使用JSON格式与服务器交互 中文乱码问题解决

    Android 使用JSON格式与服务器交互 中文乱码问题解决 参考文章: (1)Android 使用JSON格式与服务器交互 中文乱码问题解决 (2)https://www.cnblogs.com/ ...

  7. android recovery中文下载地址,Android Recovery模式与Recovery界面的中文详细说明

    Android Recovery模式与Recovery界面的中文详细说明 Android Recovery模式 来源: ChinaUnix博客 日期: 2009.04.25 22:58 (共有条评论) ...

  8. Android Studio 4以上版本设置成中文

    我们安装好Android Studio后,默认是英文界面的,这可能对开发者来说并不是很友好,所以我们给它设置成中文. 本以为直接在设置里面有切换成中文的功能,结果找了一轮没有,最后网上查看相关方法,发 ...

  9. Android实现中文汉字笔划(笔画)、中文拼音排序、英文排序

    发布时间:2018-11-16 技术:Android 概述 最近要做一个类似微信的,在登录界面选择国家地区的功能,微信有中文汉字笔画排序以及中文拼音排序等几种方式,如下所示: 简体中文 拼音排序;繁体 ...

最新文章

  1. 测试脚本的实用性(续)谈对编写脚本的几点规范
  2. 二叉查找树的简单实现
  3. 整理下Anytao《你必须知道的.Net》全文链接
  4. python学习六:数据结构
  5. 【算法分析与设计】找出缺失的一个整数问题
  6. xilinx芯片管脚使用限制_【转载】 Xilinx FPGA配置的一些细节
  7. 安卓为什么卡及其解决方案
  8. 双系统重装Ubuntu经验分享
  9. CashFiesta注册网赚
  10. 信通方恒资产评估行业快讯 - 森林资源资产抵押贷款-金融机构对抵押物进行审核与权属认定注意事项
  11. 湖南省第1届职业技能大赛(经历、总结)
  12. @RequestParam使用
  13. Intel芯片、AMD显卡有多强?M1系列呢?
  14. 设计一个自我介绍简单页面
  15. //菱形,内藏十字架
  16. 系列教程--Linux基础--12--用户和组
  17. Kubernetes 集群文件描述符测漏了...
  18. 关于IOS的Autolayout特性的理解以及使用
  19. 对于编程思想和能力有重大提升的书有哪些?
  20. 什么是Docker镜像?

热门文章

  1. Python使用wordnet工具计算词集与词条基本用法(三)
  2. python numpy 写入、读取 .npz 压缩文件
  3. Pycharm / IDEA 局部搜索功能,调试时搜索变量值,或是搜索文件名等局部搜索方法
  4. 2019西电网安实验班选拔考试
  5. PCL学习(三) SAC-IA 估记object pose
  6. 【python】-- Socket接收大数据
  7. Java基础学习总结 -- 图形用户界面GUI
  8. 穷小子做网站赚钱终得丈母娘认可
  9. EXTASPNET C# ASP.NET sql server 调用存储过程超时,解决方法
  10. 解题报告 Toy Bricks