gpt4 book ai didi

android - 扩展另一个类并在我当前的 Activity 中膨胀它的 xml 隐藏了我当前 Activity 的内容

转载 作者:行者123 更新时间:2023-11-30 01:29:29 25 4
gpt4 key购买 nike

我创建了一个导航 Activity ,其中有抽屉导航,现在当我在另一个 Activity 中扩展此类时,它可以正常工作,但其他 Activity 的内容没有显示

here is my code:
package com.astro.famouspandit.Activities.Abstract;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewStub;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.astro.famouspandit.Activities.Activity.ChartStyle;
import com.astro.famouspandit.Activities.Activity.Contact;
import com.astro.famouspandit.Activities.Activity.Settings;
import com.astro.famouspandit.R;

public class NavigationActivity extends AppCompatActivity implements View.OnClickListener{

protected DrawerLayout mDrawerLayout;

protected FrameLayout mFrameLayout_ContentFrame;
protected ActionBarDrawerToggle mActionBarDrawerToggle;
protected Toolbar mToolbar;
private LinearLayout mDrawerList2;

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

mFrameLayout_ContentFrame = (FrameLayout) findViewById(R.id.main_activity_content_frame);
mDrawerList2 = (LinearLayout) findViewById(R.id.left_drawer2);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);


mDrawerLayout = (DrawerLayout) findViewById(R.id.main_activity_DrawerLayout);
mDrawerLayout.closeDrawers();
mDrawerLayout.setStatusBarBackground(R.color.colorPrimary);

mActionBarDrawerToggle = new ActionBarDrawerToggle
(
this,
mDrawerLayout,
mToolbar,
R.string.drawer_open,
R.string.drawer_close
) {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// Disables the burger/arrow animation by default
super.onDrawerSlide(drawerView, 0);
}
};

mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);

if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
}
mActionBarDrawerToggle.syncState();

}


@Override
public void onClick(View v) {

}
public boolean onPrepareOptionsMenu(Menu menu) {
// If the nav drawer is open, hide action items related to the content view
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList2);
menu.findItem(R.id.action_Aboutus).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;


}
public boolean onOptionsItemSelected(MenuItem item){
int items = item.getItemId();
switch(items){

case R.id.action_Settings:{
Intent intent = new Intent(this,Settings.class);
startActivity(intent);

}break;

case R.id.action_Contact_us:{
Intent intent = new Intent(this,Contact.class);
startActivity(intent);

}break;

case R.id.action_Aboutus:{
Intent intent = new Intent(this,ChartStyle.class);
startActivity(intent);

}break;

case R.id.action_Profile:{
Intent intent = new Intent(this,ChartStyle.class);
startActivity(intent);

}break;
}

return super.onOptionsItemSelected(item);
}


}

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_activity_DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout android:id="@+id/left_drawer2"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"

android:background="#0F6177"/>

<!-- The main content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include layout="@layout/toolbar" />


<FrameLayout
android:id="@+id/main_activity_content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>

<!-- The navigation drawer -->


</android.support.v4.widget.DrawerLayout>

我扩展它的类:我看不到这个类的内容

public class Contact extends NavigationActivity implements View.OnClickListener {
private EditText mName,mNumber,mEmail,mMessage;
private FancyButton mSbmt;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getLayoutInflater().inflate(R.layout.activity_contact,mFrameLayout_ContentFrame);

最佳答案

我认为您正在搜索 BaseActivity 概念中使用的层次结构,您可以创建多个子对象并使用父对象的行为。正式概念是将布局从子 Activity 传递到 BaseActivityBaseActivity 将设置内容。

首先创建一个抽象类,命名为BaseActivity,应该是这样的

public abstract class BaseActivity extends AppCompatActivity{
@Override
public void onCreate(bundle) {
super.onCreate(bundle);
setContentView(getLayoutResourceId());
}

protected abstract int getLayoutResourceId();
}

然后在你的情况下在 NavigationActivity 中扩展 BaseActivity 就像这里一样

   public class NavigationActivity extends BaseActivity {
@Override
public void onCreate(bundle) {
super.onCreate(bundle);
// do extra stuff on your resources, using findViewById on your activity_navigation
}

@Override
protected int getLayoutResourceId() {
return R.layout.activity_navigation;
}
}

关于android - 扩展另一个类并在我当前的 Activity 中膨胀它的 xml 隐藏了我当前 Activity 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35970435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com