博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
初识Android
阅读量:7101 次
发布时间:2019-06-28

本文共 1049 字,大约阅读时间需要 3 分钟。

  1. 在新建项目中,如HelloWorld为例,src中的java代码中,

public class MainActivity extends Activity {

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);    -----表示给当前活动引入一个布局activity_main.xml
    }

    @Override

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

2.   Android讲究逻辑和视图分离,一般在布局文件中编写界面,在活动中引入,如上例。

3.界面上显示的helloworld!,实际上是定义在values/strings.xml中,布局中的hello_world是其键,通过其引入实际值HelloWorld!

<TextView

       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="@string/hello_world" />

4. 

<string name="app_name">HelloWorld2</string>-----app_name 在配置文件AndroidManifest.xml中会引用到。

<string name="hello_world">Hello world!</string>--hello_world在布局文件中引用到
<string name="action_settings">Settings</string>

5.  如果想引用strings.xml中的HelloWorld!字符串,有两种方式:

    • R.string.hello_world
    • @string/hello_world

转载于:https://www.cnblogs.com/huangytao/p/5529028.html

你可能感兴趣的文章
thinkphp 重定向redirect
查看>>
Builder创建者模式
查看>>
安卓应用使用QQ登录的申请流程
查看>>
Android批量图片加载经典系列——采用二级缓存、异步加载网络图片
查看>>
redis 数据类型详解 以及 redis适用场景场合
查看>>
证明 poj 1014 模优化修剪,部分递归 有错误
查看>>
node.js执行shell命令
查看>>
ASP.NET Web API获取Model元数据
查看>>
mybatis中#{}和${}的区别
查看>>
RAC安装重新运行root.sh
查看>>
Mac下面的SecureCRT(附破解方案) 更新到最新的7.3.2(转)
查看>>
jQuery实践树(2)
查看>>
投影纹理映射(Projective Texture Mapping) 【转】
查看>>
中国股市“牛”的底气来自哪里?
查看>>
北京Uber优步司机奖励政策(1月3日)
查看>>
【转】在程序中设置android:gravity 和 android:layout_Gravity属性
查看>>
Kyoya and Colored Balls(组合数)
查看>>
一起学微软Power BI系列-官方文档-入门指南(7)发布与共享-终结篇+完整PDF文档
查看>>
004杰信-关于formSubmit('factorycreate.action','_self')路径的疑惑
查看>>
tar: Cowardly refusing to create an empty archive 问题
查看>>