P111.テキストを表示する / 2.2 アプリケーションの基本を覚える

Android開発に関するメモランダム

カテゴリー: Android Studio ではじめる Android プログラミング入門 第3版 Android Studio 2対応  閲覧数:369 配信日:2018-03-14 10:44


activity_main.xmlを開く


画面下にある「Design」タグをクリックしてデザインツールへ切り替える

左側にあるパレットから「Text」から「TextView」部品をドラッグし、パレットの右のデザインする領域にドロップして配置
・配置した部品を選択し、プロパティから以下の項目に値を設定
layout.width 「match_constraint」を選択
text 「Hello Android!」と設定
textSize 「36sp」と設定
画面下にある「Text」タグをクリックしてXMLのソースコード表示画面へ切り替える
▼L:\Android\AndroidStudioProject\App20180302\app\src\main\res\layout\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="tokyo.w3c.android0.app20180302.MainActivity">

   <TextView
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:text="Hello World!"
       android:textSize="36sp"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintLeft_toLeftOf="parent"
       app:layout_constraintRight_toRightOf="parent"
       app:layout_constraintTop_toTopOf="parent"
       tools:text="Hello Android!" />

</android.support.constraint.ConstraintLayout>



切り替わらず苦しむ


Android Studio 側でコードを修正し、スマホにアプリを再読み込み
・実機デバッグだから?
・エミュレーターで試す
・まさかの「Hello World!」
・なんでやねん!


原因判明


「tools:text」を記述している場合は、こちらの変更も必要
・画面下にある「Text」タグをクリックしてソースコード画面へ切り替える
▼L:\Android\AndroidStudioProject\App20180302\app\src\main\res\layout\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="tokyo.w3c.android0.app20180302.MainActivity">

   <TextView
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:text="Hello Android!"
       android:textSize="36sp"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintLeft_toLeftOf="parent"
       app:layout_constraintRight_toRightOf="parent"
       app:layout_constraintTop_toTopOf="parent"
       tools:text="Hello Android!" />

</android.support.constraint.ConstraintLayout>




TextView の android:text と tools:text について
Tools Attributes Reference


週間人気ページランキング / 2-16 → 2-22
順位 ページタイトル抜粋 アクセス数
アクセスが、ありませんでした! 0
2025/2/23 1:01 更新
指定期間人気ページランキング / 1970-1-1 → 2025-2-22
順位 ページタイトル抜粋 アクセス数
アクセスが、ありませんでした! 0
2025/2/23 1:01 更新