私には2つの活動があります:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void click(View view) {
Intent intent= new Intent(this, TranslucentActivity.class);
startActivity(intent);
}
}
public class TranslucentActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
this.setTheme(android.R.style.Theme_Translucent);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_translucent);
}
}
レイアウトactivity_main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:onClick="click" />
</RelativeLayout>
レイアウトactivity_translucent
<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=".TranslucentActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Hello_world" />
</RelativeLayout>
マニフェスト
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.translucencytest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.translucencytest.MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.translucencytest.TranslucentActivity">
</activity>
</application>
</manifest>
MainActivityのボタンをクリックすると、透明な背景でTranslucentActivityが起動します。プラットフォーム4.0.3のAndroidエミュレーターではすべて正常に見えますが、2.3.3や4.2などの他のプラットフォームでは、透明ではなく黒の背景が表示されます。何が間違っている可能性がありますか?
PS私はマニフェストを使って活動のテーマを宣言したくありません。