我尝试使用activity_main(xml)
将MainActivity的布局从firebase(xml)
更改为setContentView()
。
问题是,即使我已将活动更改为firebase layout
,活动开启时仍会显示activity_main布局。这是我的代码
在更改为firebase(xml)之前
public class MainActivity extends SimpleActivity {
private FirebaseAuth mAuth;
private EditText email, password;
@Override
protected void onCreate(Bundle savedInstanceState) {
mAuth = FirebaseAuth.getInstance();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
更改为firebase(xml)后
public class MainActivity extends SimpleActivity {
private FirebaseAuth mAuth;
private EditText email, password;
@Override
protected void onCreate(Bundle savedInstanceState) {
mAuth = FirebaseAuth.getInstance();
super.onCreate(savedInstanceState);
setContentView(R.layout.firebase);
}
activity_main xml的XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:gravity="center">
firebase xml的XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:gravity="center"
android:id="@+id/firebase"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.johnson.myapplication.MainActivity">
请注意这两个属性
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.johnson.myapplication.MainActivity">
正式用于activity_main布局。我删除了它并将其添加到firebase布局属性