Android Studio 输出文本总是“Hello from C++" [英] Android Studio output text always 'Hello from C++'

查看:36
本文介绍了Android Studio 输出文本总是“Hello from C++"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正面临这个奇怪的问题,我在 activity_main.xml 中创建了一个 textview 并将文本设置为:android:text="Oh my上帝"但是无论我放什么文字,应用屏幕上的输出都是:

I'm facing this weird problem, I've created a textview in activity_main.xml and set text as: android:text="Oh my god" But no matter to whatever the text I put, the output in app screen is:

来自 C++ 的你好

事实上,文本的位置根据我的设置而变化,但不幸的是,文本始终保持不变.我试过删除并再次添加 textview 但没有改变.

In fact, the position of text changes according to my setting but the text always remains unfortunately unchanged. I've tried removing and again adding textview but no change.

MainActivity.java:

MainActivity.java:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    // Example of a call to a native method
    TextView tv = (TextView) findViewById(R.id.sample_text);
    tv.setText(stringFromJNI());
    }

activity_main.xml:

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/sample_text"
        android:layout_width="147dp"
        android:layout_height="76dp"
        android:layout_marginStart="248dp"
        android:layout_marginTop="16dp"
        android:text="Oh my god"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

PS:有些人有同样的问题,但尚未得到答复.

PS: Some guy has this same problem but wasn't answered yet.

推荐答案

这是你的问题:

tv.setText(stringFromJNI());

将文本设置为 stringFromJNI() 返回的任何内容,替换您在 XML 中定义的内容.

That sets the text to whatever stringFromJNI() returns, replacing what you define in the XML.

如果您想更改显示的文本,请修改本机方法以返回您想要的内容,删除编程设置,或更改您在代码中设置文本的内容.

If you want to change the text that is displayed, either modify the native method to return what you want, remove the programmatic setting, or change what you set the text to in your code.

这篇关于Android Studio 输出文本总是“Hello from C++"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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