我有两个活动:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
布局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>
Run Code Online (Sandbox Code Playgroud)
布局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>
Run Code Online (Sandbox Code Playgroud)
表现 …