无法移至主要活动

时间:2018-11-22 03:45:51

标签: android android-studio android-layout android-activity

问题:我想有意移动MainActivity,但我将LoginActivity用作主显示,如何在MainActivity不是主显示的同时移至MainActivity?

我想我搞砸了。仍然需要帮助。

LoginActivity.java

public class LoginActivity extends AppCompatActivity implements View.OnClickListener {

EditText etEmail;
EditText etPassword;
Button btnRegister;
Button btnLogin;

public static Intent getIntent(Context context){
    return new Intent (context, LoginActivity.class );
}


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);


    ButterKnife.bind(this);
    //setTitle(getString(R.string.activity_main_new_title));
    //enableBackButton();

    setupViews();

}

private void setupViews() {
    btnRegister = (Button) findViewById(R.id.btn_register);
    btnRegister.setOnClickListener(this);
    btnLogin = (Button) findViewById(R.id.btn_login);
    btnLogin.setOnClickListener(this);
}


@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.btn_register:
        Intent intentRegister = new Intent(getApplicationContext(), RegisterActivity.class);
        startActivity(intentRegister);
        break;
        case R.id.btn_login:
        Intent intentLogin = new Intent(getApplicationContext(), MainActivity.class);
        startActivity(intentLogin);
        break;

        default:
            break;
    }
}

}

MainActivity

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    startActivity(LoginActivity.getIntent(this));
}

}

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.teltics.projectnew">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".activities.MainActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".activities.LoginActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar"
        android:parentActivityName=".activities.LoginActivity"
        >
    </activity>
    <activity
        android:name=".activities.RegisterActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize"
        android:label="Register"
        android:theme="@style/AppTheme.NoActionBar"
        android:parentActivityName=".activities.LoginActivity">
    </activity>
    <activity
        android:name=".activities.ProfileActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
    </activity>
</application>

activity_main.xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/toolbar_background_color"
    android:orientation="horizontal"
    android:gravity="center">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/default_component_margin"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_toolbar_logo"
        />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/ic_default_background"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:padding="@dimen/default_component_padding">

    <EditText
        android:id="@+id/et_email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/default_component_margin_very_big"
        android:inputType="textEmailAddress"
        android:textColorHint="#EEEEEE"
        android:textColor="@color/default_text_color_inverse"
        android:background="#77000000"
        android:hint="@string/text_view_email_hint"
        />

    <EditText
        android:id="@+id/et_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/default_component_margin"
        android:inputType="textPassword"
        android:textColorHint="#EEEEEE"
        android:textColor="@color/default_text_color_inverse"
        android:background="#77000000"
        android:hint="@string/text_view_password_hint"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/default_component_margin"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btn_register"
            android:layout_width="0dp"
            android:layout_weight="0.5"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:textColor="@color/black"
            android:text="@string/button_register_text"
            />

        <View
            android:layout_width="@dimen/default_component_margin"
            android:layout_height="1dp"
            />

        <Button
            android:id="@+id/btn_login"
            android:layout_width="0dp"
            android:layout_weight="0.5"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:textColor="@color/black"
            android:text="@string/button_login_text"
            />

    </LinearLayout>

    <Button
        android:id="@+id/btn_forgot_password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/default_component_margin"
        android:layout_gravity="center_horizontal"
        android:background="@color/white"
        android:textColor="@color/black"
        android:text="@string/button_forgot_password_text"
        />

</LinearLayout>

感谢您对我的帮助,对您的帮助很重要

1 个答案:

答案 0 :(得分:0)

尝试一下

您的清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.teltics.projectnew">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".activities.LoginActivity"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".activities.MainActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar"
        android:parentActivityName=".activities.MainActivity"
        >
    </activity>
    <activity
        android:name=".activities.RegisterActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize"
        android:label="Register"
        android:theme="@style/AppTheme.NoActionBar"
        android:parentActivityName=".activities.LoginActivity">
    </activity>
    <activity
        android:name=".activities.ProfileActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
    </activity>
</application>