Android开发笔记(一)
来源:互联网 发布:树莓派能做什么 知乎 编辑:程序博客网 时间:2024/05/20 02:27
java没有多少基础,学过面向对象 ,但是基本上都忘记了,现在开始学习Android,将自己出现的一些错误以及问题写出来,以后自己看和大家一起学习。小白一只,有错误希望大家指出来,这样才能成长嘛(可爱脸)!
2016年5月18日18:22:00
1、当 android:orientation=”vertical” 时, 只有水平方向的设置才起作用,垂直方向的设置不起作用。即:left,right,center_horizontal 是生效的。
2、当 android:orientation=”horizontal” 时, 只有垂直方向的设置才起作用,水平方向的设置不起作用。即:top,bottom,center_vertical 是生效的。
2016年5月19日14:30:54
1、在文本框中显示背景提示文字(Edit a Message),在activity_main.xml里面里面写上android:hint="@string/edit_message"/>
,然后在string.xml里面初始相应的值<string name="edit_message">Enter a Message</string>
2、如果在res目录下面没有menu目录,可以新建一个,但是新建的xml文件总会选择为Values还是Layout的,无法保证建立的xml在menu目录下面
方法:建立好menu文件后,右键menu目录建立一个menu resource file文件,命名即可。
2016年5月20日22:01:40
打开android studio后,在Android monitor中总是显示“No Debuggable Applications”
解决方法:进入 android studio , 依次选择Tools-> Android -> Enable ADB Integration
. 然后就不会出现“No Debuggable Applications”的提示了
2016年5月21日18:19:49
使用隐示Intent时候出现这样的错误:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.example.chencong.activitytestintent.ACTION_START cat=[com.example.chencong.activitytestintent.MY_CATEGORY] }
错误信息提示,没有任何一个活动可以响应我们的Intent。
原因:在Intent中新增了一个category,而SecondActivity的<intent-filter>
标签中并没有声明可以响应这个category,所以就会出现没有任何活动可以响应该Intent的情况。
解决方法:在AndroidManifest.xml的<intent-filter>
中添加一个category的声明。
<category android:name="com.example.chencong.activitytestintent.MY_CATEGORY"/>
下面为<activity>
中代码:
<activity android:name=".ThirdActivity"> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="tel"/> </intent-filter> </activity>
2016年5月21日19:47:25
使用Intent传递参数时,程序能够执行成功但是在接受参数的活动页面没有显示参数。
接受页面(SecondActivity)的onCreate()方法:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second_layout); /*从Intent中取值*/ Intent intent=getIntent(); String date=intent.getStringExtra("extra_data"); Log.d("SecondActivity",date); /*在日志中打印*/ }
修改之后的onCreate()方法,创建一个TextView来显示参数:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second_layout); /*从Intent中取值*/ Intent intent=getIntent(); String date=intent.getStringExtra("extra_data"); // Create the text view TextView textView = new TextView(this); textView.setTextSize(20); textView.setText(date); setContentView(textView); Log.d("SecondActivity",date); /*在日志中打印*/ }
向上面那样将代码修改后就好了。正确执行,并且能够显示参数了。
顺带说一下传递参数的活动的onCreate()方法的书写,使用显示Intent传递参数:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.first_layout); Button button=(Button)findViewById(R.id.button_1); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /*显示点击了这个按钮,可以不要*/ Toast.makeText(FirstActivity.this,"传递参数中...",Toast.LENGTH_SHORT).show(); String data="hello SecondActivity"; Intent intent=new Intent(FirstActivity.this,SecondActivity.class); intent.putExtra("extra_data",data); startActivity(intent); } }); }
2016年5月21日20:56:23
小白一只,菜鸟一个,但是我有个愿望:
我挥舞着键盘和本子,发誓要把世界写个明明白白。 ——《第一行代码Android·郭霖》
学习Android第3
天
- Android开发笔记(一)
- Android开发笔记(一)
- Android开发笔记<一>
- Android游戏开发学习笔记(一)
- Android开发新手学习笔记(一)
- Android 开发学习笔记 (一)
- Android开发学习笔记(一)
- Android平台应用开发笔记(一)
- Android项目开发笔记(一)
- Android开发学习笔记--基础知识(一)
- android开发笔记之animation(一)
- Android开发秘籍学习笔记(一)
- ANDROID开发笔记(一)环境搭建
- Android插件化开发笔记(一)
- Android 应用开发笔记(一)
- Android开发学习笔记(一)
- android开发笔记之Makefile(一)
- android开发笔记汇总(一)
- 学会自己测天气-----04
- OpenCV实践之路——人脸识别之三识别自己的脸
- 基于反馈结构的窄带宽陷波滤波器
- Java基础(三)
- flume学习(五):flume将log4j日志数据写入到hdfs
- Android开发笔记(一)
- zabbix3.0.2 监控mysql服务down的时候不触发报警的问题修复
- CSDN启航
- python通过pyhdfs连接hdfs的安装配置
- flume学习(六):使用hive来分析flume收集的日志数据
- 剑指offer面试题4(java实现)
- 关于sample per symbol(sps)
- 《Android5从入门到精通》
- C++ 中类模板