動画の内容
前回学習した「文字枠の追加」の「文字枠」を非表示にする方法です。
この動画の前に「文字枠の追加」を済ませておいてください。

応用で「タイトルボタンを非表示にする」などかなり幅広く使える命令です。

activity_main.xml (完成)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/character" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/charText"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textSize="40dp"
android:layout_marginBottom="20dp" />
</RelativeLayout>
MainActivity.java (完成)
アプリケーション起動時に文字枠(TextView)の非表示
package com.test.test; // この行はコピペするとエラーが出ます。(アプリ毎に違う内容になる)
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 文字枠の非表示
findViewById(R.id.charText).setVisibility(View.INVISIBLE);
}
// 以下略 (変更不要)
}
ポイント
findViewById(R.id.●●).setVisibility(View.INVISIBLE);


activity_main.xml (おまけ・非表示→表示)
アプリケーション起動時に非表示 → オプションメニュー選択で表示
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/character" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/charText"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textSize="40dp"
android:layout_marginBottom="20dp" />
</RelativeLayout>
