Toast的标准格式和自定义格式
来源:互联网 发布:ipad看文献软件 编辑:程序博客网 时间:2024/05/11 03:00
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:id="@+id/show" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Show Toast"/></LinearLayout>
customtoast.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_height="wrap_content" android:layout_width="wrap_content"android:background="#ffffffff" android:orientation="vertical"android:id="@+id/llToast" ><TextViewandroid:layout_height="wrap_content"android:layout_margin="1dip"android:textColor="#ffffffff"android:layout_width="fill_parent"android:gravity="center"android:background="#bb000000"android:id="@+id/tvTitleToast" /><LinearLayoutandroid:layout_height="wrap_content"android:orientation="vertical"android:id="@+id/llToastContent"android:layout_marginLeft="1dip"android:layout_marginRight="1dip"android:layout_marginBottom="1dip"android:layout_width="wrap_content"android:padding="15dip"android:background="#44000000" ><ImageViewandroid:layout_height="wrap_content"android:layout_gravity="center"android:layout_width="wrap_content"android:id="@+id/tvImageToast" /><TextViewandroid:layout_height="wrap_content"android:paddingRight="10dip"android:paddingLeft="10dip"android:layout_width="wrap_content"android:gravity="center"android:textColor="#ff000000"android:id="@+id/tvTextToast" /></LinearLayout></LinearLayout>
MainActivity.java
package com.andyidea.demo;import android.app.Activity;import android.os.Bundle;import android.view.Gravity;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.Button;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.TextView;import android.widget.Toast;public class MainActivity extends Activity {Button btn; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btn = (Button)findViewById(R.id.show); btn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//标准方式showToast1();//标准方式上添加图片showToast2();//自定义显示方式showToast3();}}); } /** * Basic Standard Toast * 标准提示信息方式 */ private void showToast1(){ Toast toast = Toast.makeText(getApplicationContext(),"Hello, This is Andy!", Toast.LENGTH_LONG); toast.show(); } /** * Adding an Image to the Standard Toast * 在标准显示方式基础上添加图片 */ private void showToast2(){ Toast toast = Toast.makeText(getApplicationContext(),"Hello, This is Andy!", Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); LinearLayout toastView = (LinearLayout) toast.getView(); ImageView imageCodeProject = new ImageView(getApplicationContext()); imageCodeProject.setImageResource(R.drawable.icon); toastView.addView(imageCodeProject, 0); toast.show(); } /** * Creating a Toast with Custom Layout * 创建自定义的提示信息方式 */ private void showToast3(){ LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.customtoast, (ViewGroup) findViewById(R.id.llToast)); ImageView image = (ImageView) layout.findViewById(R.id.tvImageToast); image.setImageResource(R.drawable.page); TextView title = (TextView) layout.findViewById(R.id.tvTitleToast); title.setText("Attention"); TextView text = (TextView) layout.findViewById(R.id.tvTextToast); text.setText("Hello, This is Andy!"); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); }}
- Toast的标准格式和自定义格式
- Android中的Toast的标准格式和自定义格式
- Android中的Toast的标准格式和自定义格式
- Android中的Toast的标准格式和自定义格式
- 标准的json格式
- 【备用】标准CSS引用自定义字体格式
- 自定义Toast格式,觉得有用,就记录下来了
- 自定义标签的格式:
- 自定义的转换格式
- 光盘的标准与格式
- 本科毕业论文的标准格式
- 标准的函数注释格式
- 键盘输入数据的标准格式
- java注释的标准格式
- 采用RFC2833标准进行DTMF传送的方法和格式。
- C语言 时间戳和标准格式的转换
- C语言 时间戳和标准格式的转换
- 使用标准的格式:WKT、WKB和GML(1)
- 系统性能分析
- mysql创建数据库指定字符集
- 基于OPC 技术的上位机与S7-200 系列PLC通讯的实现
- MyEclipse各种版本注册码
- 寻找第K大的数的方法总结
- Toast的标准格式和自定义格式
- sql语句大全(一)
- 获取文件的后缀名称,并且全部化成成小写字母返回
- Mysql字符集设置
- myeclipse maven project .classpath
- oracle 批量提交和回滚
- Python正则表达式中的 compile,search,group,groups 函数的简单说明
- 搭建 adb 环境,不用在进入目录后再使用adb命令了
- 斐波那契数列时间复杂度分析