如何在Android应用程序打印消息 [英] How to print message in an Android App

查看:224
本文介绍了如何在Android应用程序打印消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我开始学习如何编写Android应用的第一次,但我遇到了问题。

当我去string.xml文件中输入一条消息,在屏幕上打印出来。而不是打印我的信息将打印的Hello World。还应当指出的是,我下面这个教程:

http://www.raywenderlich.com/78574/android-tutorial-for-beginners-part-1#comments

和他们的教程,是说要一个Hello World字符串改变我自己的自定义消息的声明。问题是,当我打开文件没有的Hello World字符串。 (但应用程序打印Hello World反正。),当我走出我的方式,使每例如一个Hello World声明。

在我修改了文件:

 <资源>
   <字符串名称=APP_NAME> OMG Android和LT; /串>
   <字符串名称=action_settings>设置< /串>
 < /资源>

在我修改了文件:

 <资源>
   <字符串名称=APP_NAME> OMG Android和LT; /串>
   <字符串名称=action_settings>设置< /串>
   <字符串名称=参考hello world> Dpolaristar是编程Android和LT; /串>
 < /资源>

该应用程序打印Hello World,而不在个人信息呢。我很困惑,谁能告诉我,如果有某种自动倍率还是在那里说给打印世界您好,我可以覆盖能力的项目别处。我已经看了,但我无法找到任何东西。

我的问题也似乎是奇怪特定这让我觉得我不是摸过的东西我不应该或者我使用不同版本的Andr​​oid影城则教程的作者。

帮助?

编辑:

我设法给activity_main.xml中的文本视图以添加引用。问题是有没有的TextView节下添加

下面是我没有为参考更改文件的复制和粘贴:

 <?XML版本=1.0编码=UTF-8&GT?;
< android.support.design.widget.CoordinatorLayout
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s的android:layout_width =match_parent
    机器人:layout_height =match_parent机器人:fitsSystemWindows =真
    工具:上下文=MainActivity。>   < android.support.design.widget.AppBarLayout机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =match_parent

安卓主题=@风格/ AppTheme.AppBarOverlay>

 < android.support.v7.widget.Toolbar机器人:ID =@ + ID /工具栏
        机器人:layout_width =match_parent机器人:layout_height =?ATTR / actionBarSize
        ?ATTR / colorPrimary:Android的背景=应用:popupTheme =@风格/ AppTheme.PopupOverlay/>    < /android.support.design.widget.AppBarLayout>    <包括布局=@布局/ content_main/>    < android.support.design.widget.FloatingActionButton机器人:ID =@ + ID / FAB
    机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =底部|结束机器人:layout_margin =@扪/ fab_margin
    机器人:SRC =@机器人:可绘制/ ic_dialog_email/>    < /android.support.design.widget.CoordinatorLayout>

编辑2:我环顾四周我的项目,并已发现,在content_main.xml的设计视图我不显示我输入的字符串值,只是没有当我运行的应用程序对我的片剂。

这是否给任何人任何线索?


解决方案

首先属性名必须是参考hello world ,请勿使用资本的字符,它会导致您proyect的问题!

 <字符串名称=参考hello world>达里尔是学习Android和LT;!/串>

然后,只需添加引用:

 <的TextView
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=@字符串/参考hello world/>

然后你会看到这句话达里尔是学习Android的!在显示你的的TextView

<字符串名称=参考hello world>达里尔是学习Android和LT;!/串>
必须里面设置好的 /res/values​​/strings.xml

要打开包含布局的TextView 转至 /res/layout/activity_main.xml / RES /布局/ activity_my.xml 就像在你的榜样。

Hi I'm starting to learn how to write Android Apps for the first time but I'm running into problems.

When I go to the string.xml file to enter a message to be printed on the screen. Instead of printing my message it prints "Hello World." It should also be noted that I'm following this tutorial:

http://www.raywenderlich.com/78574/android-tutorial-for-beginners-part-1#comments

And in their tutorial there is a statement that says to change a hello world string to my own custom message. Problem is when I opened the file there was no hello world string. (But the app prints hello world anyway.) And when I go out of my way to make a hello world statement per the example.

Before I modified the file:

  <resources>
   <string name="app_name">OMG Android</string>
   <string name="action_settings">Settings</string>
 </resources>

After I modified the file:

 <resources>
   <string name="app_name">OMG Android</string>
   <string name="action_settings">Settings</string>
   <string name="Hello_World">Dpolaristar is programming in Android</string>
 </resources>

The app prints Hello World without the personal message anyway. I'm confused, can anyone tell me if there is some sort of automatic override or somewhere else in the project where it says give the ability to print Hello World that I can override. I already looked but I can't find anything.

My problem also seems to be oddly specific which makes me think I either touched something I shouldn't have or maybe I'm using a different version of Android Studios then the author of the tutorial.

Help?

EDIT:

I managed to get to the text view of the activity_main.xml to add the reference. Problem is there is no textview section to add under.

Here is a copy and paste of the file which I DID NOT change for reference:

     <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"  android:layout_width="match_parent"
    android:layout_height="match_parent" android:fitsSystemWindows="true"
    tools:context=".MainActivity">

   <android.support.design.widget.AppBarLayout   android:layout_height="wrap_content"
    android:layout_width="match_parent"

android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
        android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"  app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <android.support.design.widget.FloatingActionButton  android:id="@+id/fab"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

    </android.support.design.widget.CoordinatorLayout>       

EDIT 2:I've looked around my project and have found that in the DESIGN view of the content_main.xml I does show the value for the string I typed just not when I run the app ON MY TABLET!

Does this give anyone any clues?

解决方案

first of all the property name must be "hello_world", don´t use capital characters, it will cause problems in your proyect!

<string name="hello_world">Darryl is learning Android!</string>

Then just add the reference:

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

Then you will see the sentence Darryl is learning Android! displayed in your TextView.

The value <string name="hello_world">Darryl is learning Android!</string> must be setted inside /res/values/strings.xml

To open the layout that contains the TextView go to /res/layout/activity_main.xml or /res/layout/activity_my.xml like in your example.

这篇关于如何在Android应用程序打印消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆