如何以编程方式隐藏我的应用程序窗口?
可能吗?
setContentView( R.layout.screen1 );
此编码启动应用程序窗口。如何隐藏此窗口。可能吗?
谢谢。
试试这个,
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Put you code to hide the layout
RelativeLayout mLayout = (RelativeLayout) findViewById(R.id.mainLayout);
mLayout.setVisibility(View.GONE);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="96dp"
android:text="Button" />
</RelativeLayout>
是的,有可能。为 screen1 布局的父窗口提供一个 id,例如:
android:id="@+id/main_layout"
当你想隐藏它时,写如下:
final LinearLayout mainLayout = (LinearLayout)findViewById(R.layout.main_layout); // assuming its a LinearLayout
mainLayout.setVisibility(View.GONE);