zoukankan      html  css  js  c++  java
  • 安卓笔记之配置第一个程序

    配置一个简单的程序

    主要通过src

                                |-java

    和       res

                                |-layout

                                    |-main.xml

    以及        |-values

                                         |-strings.xml   来完成

    第一个在strings.xml没有参与的情况下通过ID搭配配置文件

             在main.xml下配置textview和button

                               <TextView

            android:id="@+id/mytext"     -->要调取的ID

            android:layout_width="fill_parent"  ----》宽度

            android:layout_height="wrap_content" ----》高度

           />

        <Button

            android:id="@+id/mybut"    -->按钮ID

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

       />

    然后在java程序中来调取

        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            TextView text = (TextView) super.findViewById(R.id.mytext);//取得TextView组件

            text.setText(“中国人”);//设置显示文字

            Button but= (Button) super.findViewById(R.id.mybut);//取得按钮组件

            but.setText(“按我”);

        }

    第二种在strings参与的情况下

        一时strings参与xml

        <TextView

            android:id="@+id/mytext"     -->要调取的ID

            android:layout_width="fill_parent"  ----》宽度

            android:layout_height="wrap_content" ----》高度

            android:text="@strings/text" -->要展示的文本 />

        <Button

            android:id="@+id/mybut"    -->按钮ID

            android:layout_width="fill_parent"

            android:layout_height="wrap_content"

            android:text="@strings/msg" />

        public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            //TextView text = (TextView) super.findViewById(R.id.mytext);//取得TextView组件

            //text.setText(“中国人”);//设置显示文字

            //Button but= (Button) super.findViewById(R.id.mybut);//取得按钮组件

            //but.setText(“按我”);

        }

        二是strings参与java

        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            TextView text = (TextView) super.findViewById(R.id.mytext);//取得TextView组件

            text.setText(R.string.text);//设置显示文字

            Button but= (Button) super.findViewById(R.id.mybut);//取得按钮组件

            but.setText(R.string.msg);

        }

    这两种情况都要在strings中添加

    <resources>

     

        <string name="hello">Hello World, ZhActivity!</string>

        <string name="app_name">Zh</string>

        <string name="text">中国人</string>

        <string name="msg">按我</string>

     

    </resources>

    第三种情况

    通过程序动态生成

      public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            LinearLayout layout = new LinearLayout(this);

            TextView text = new TextView(this);

            text.setText(super.getString(R.string.text));//通过strings.xml文件设置文字

            Button but = new Button(this);//定义按钮

            but.setText(super.getString(R.string.msg));//配置组件文字

            layout.addView(text);//向布局管理器之中增加文本组件

            layout.addView(but);//想布局管理器之中增加按钮组件

            super.setContentView(layout);//设置要使用的布局管理器

        }

  • 相关阅读:
    Github优秀java项目集合(中文版)
    gradle 将依赖打入Jar包的方法
    早期malloc分配时,如果内存耗尽分配不出来,会直接返回NULL。现在分配不出来,直接抛出异常(可使用nothrow关键字)
    最想挖的各家互联网公司最牛职位人才(哪方面值得去、值得学)
    C++使用libcurl做HttpClient(业务观摩,用C++封装过程式代码,post和get的数据,最好url编码,否则+会变成空格)good
    【C/S通信交互之Http篇】Cocos2dx(Client)使用Curl与Jetty(Server)实现手机网游Http通信框架(内含解决curl.h头文件找不到问题)
    PHP模拟POST提交数据并获得返回值之CURL方法(使用PHP extension,然后使用php_curl.dll,很不错)
    SignalR实现B/S系统对windows服务运行状态的监测
    滴滴出行秋招编程题
    Tag Helpers 介绍
  • 原文地址:https://www.cnblogs.com/kakaxi/p/2243096.html
Copyright © 2011-2022 走看看