xml で定義されたアクティビティに 2 つのテキストビューがあります。どちらも背景色が灰色です。私のアプリでは、テキストビューの背景色の 1 つを青に設定しました。これは期待どおりに機能します。
BUT : デバイスを回したり (回転させたり)、アプリを終了して再び戻ってくると、もう一方のテキストビューも青色で、意図的に設定したものと同じ色になります...!?
アプリを終了して再度起動すると、2 番目のテキストビューは青色のままです。アプリの実行を停止 (強制終了) して再度起動すると、2 番目のテキストビューが灰色になります。しかし、次回デバイスを回転させるか、アプリを起動するとすぐに同じ問題が発生します。
問題のデバイスは 4.1.1 を実行しています。- 2.3.4 デバイスで同じアプリを問題なく実行できます。
SDK ツール 22.0.1、Eclipse Juno サービス リリース 2 32 ビット、Windows 7 64 ビット
編集: SDK ツール 14、Windows 7 32 ビット上の Eclipse Indigo SR1 32 ビットで同じ問題
そこで何が起こっているのかわかりません。それはある種の望ましくないMAGICです。手伝っていただけませんか?
以下は、問題のプロジェクトから変更されていない実際のソース コードです。
MainActivity.java:
package com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv1 = (TextView) findViewById(R.id.textView1);
tv1.setBackgroundColor(0xff33b5e5);
}
}
活動_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="#cccccc" />
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_marginTop="20dp"
android:background="#cccccc" />
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:icon="@drawable/ic_launcher"
android:label="TextView Test" >
<activity android:name="com.example.test.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
編集 2:さらに奇妙なことに: textview2 の色を #cdcdcd に少し変更すると、問題は発生しません。これは、両方の色 (textview1 と textview2) が XML で同じである場合のみです。