Android开发——提示信息框无法显示
来源:互联网 发布:jennifer lopez知乎 编辑:程序博客网 时间:2024/06/01 09:18
最近初学安卓开发,发现练习提示信息框时,魅族MX5手机上怎么都显示不出来提示的信息,最后,打开安卓模拟器,发现模拟器可以正常显示
.java文件代码如下:
public class MainActivity extends Activity {public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.fragment_main);Button simple = (Button) findViewById(R.id.button1);// 为按钮的单击事件绑定事件监听器simple.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View source){// 创建一个Toast提示信息Toast toast = Toast.makeText(MainActivity.this, "谁让你点的"// 设置该Toast提示信息的持续时间, Toast.LENGTH_SHORT);toast.show();}});Button bn = (Button) findViewById(R.id.button2);// 为按钮的单击事件绑定事件监听器bn.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View source){// 创建一个Toast提示信息Toast toast = new Toast(MainActivity.this);// 设置Toast的显示位置toast.setGravity(Gravity.CENTER, 0, 0);// 创建一个ImageViewImageView image = new ImageView(MainActivity.this);image.setImageResource(R.drawable.a111);// 创建一个LinearLayout容器LinearLayout ll = new LinearLayout(MainActivity.this);// 向LinearLayout中添加图片、原有的Viewll.addView(image);// 创建一个TextViewTextView textView = new TextView(MainActivity.this);textView.setText("你想多了吧");// 设置文本框内字号的大小和字体颜色textView.setTextSize(24);textView.setTextColor(Color.MAGENTA);ll.addView(textView);// 设置Toast显示自定义Viewtoast.setView(ll);// 设置Toast的显示时间toast.setDuration(Toast.LENGTH_LONG);toast.show();}});}}
fragement_main.xml文件如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.taitai.MainActivity$PlaceholderFragment" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="51dp" android:layout_marginTop="24dp" android:text="这个点了有惊喜呦" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button1" android:layout_below="@+id/button1" android:layout_marginTop="24dp" android:text="这个点了可以看美图呦" /></RelativeLayout>
0 0
- Android开发——提示信息框无法显示
- android开发-使用Toast显示提示信息框
- .Android开发在Eclipse环境中无法显示提示信息This element neither has attached
- Android开发:快速显示提示信息机…
- 在android显示 提示信息
- Android—AlertDialog提示信息
- 鼠标提示——在鼠标当前位置显示提示信息
- 鼠标提示——在鼠标当前位置显示提示信息
- 密码框显示提示信息
- 密码框显示提示信息
- Android 自定义PopupWindow 显示提示帮助信息
- Android 自定义PopupWindow 显示提示帮助信息
- 使用bootstrapValidator无法正常显示提示信息的问题
- Android 开发ADT 出现无法智能提示
- 使用Toast显示提示信息框
- 使用Toast显示提示信息框
- jquery 鼠标悬停显示信息提示框
- android 信息提示框 Toast
- Linux基础--->命令(一)
- java并发包-ReentrantLock(四):Condition
- c++作业3
- R-Studio如何恢复被格式化移动硬盘数据
- 利用POSIX文件函数部分实现linux中的cp功能
- Android开发——提示信息框无法显示
- 腾讯云Ubuntu14.04如何安装JDK1.8
- MYSQL执行计划explain
- Atitit 数据库view视图使用推荐规范与最佳实践与方法
- 八大排序---归并排序
- The operator || is undefined for the argument type(s) int, int
- PAT1010
- Android 自定义复合控件之通用标题栏
- JDBC-马士兵教程