Navigation drawer hide the content of the extending activities










0














I try to get a navigation drawer that can be used for every activity (in kotlin). Unfortunately the content of the activities isn't shown if I extend the NavigationDrawerActivity. I know there are a lot of questions about this topic but the already given answers couldn't fix my problem.



I toke the most from the Android Studio Navigation layout so my NavigationDrawerActivity looks like this:



abstract class NavigationDrawerActivity : AppCompatActivity(), 
NavigationView.OnNavigationItemSelectedListener

override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.nav_layout)
setSupportActionBar(toolbar)

val toggle = ActionBarDrawerToggle(
this, drawer_layout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close
)
drawer_layout.addDrawerListener(toggle)
toggle.syncState()

nav_view.setNavigationItemSelectedListener(this)


override fun onBackPressed()
if (drawer_layout.isDrawerOpen(GravityCompat.START))
drawer_layout.closeDrawer(GravityCompat.START)
else
super.onBackPressed()



override fun onNavigationItemSelected(item: MenuItem): Boolean
// Handle navigation view item clicks here.
when (item.itemId)
//Handle selected item


drawer_layout.closeDrawer(GravityCompat.START)
return true




The belonging layoutfile:



<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="start"
tools:openDrawer="start">

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:context=".NavigationDrawerActivity">

<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>

</android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView

android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"/>

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


Now when I create an activity extending the navigation the content of the layout of the activity (activity_main) isn't shown.



class MainActivity : NavigationDrawerActivity() 

override fun onCreate(savedInstanceState: Bundle?)
setContentView(R.layout.activity_main)
super.onCreate(savedInstanceState)





Maybe it's because of the order of the two statements in the MainActivity:



 setContentView(R.layout.activity_main)
super.onCreate(savedInstanceState)


But if I change the order I can see my content, but not the Navigation.



Does anybody know my error?










share|improve this question























  • It's impossible to do it like that. You can't setContentView() twice and get merge effect
    – Stanislav Bondar
    Nov 12 at 12:19










  • So it's wrong to have this call in both activities right? Do you know how I can change my code? Is the only way to work with fragments?
    – Sabi
    Nov 12 at 13:17










  • So I guess I have to include a FrameLayout to my layout file. Can anybody tell me how to work with that without using fragments?
    – Sabi
    Nov 13 at 9:40















0














I try to get a navigation drawer that can be used for every activity (in kotlin). Unfortunately the content of the activities isn't shown if I extend the NavigationDrawerActivity. I know there are a lot of questions about this topic but the already given answers couldn't fix my problem.



I toke the most from the Android Studio Navigation layout so my NavigationDrawerActivity looks like this:



abstract class NavigationDrawerActivity : AppCompatActivity(), 
NavigationView.OnNavigationItemSelectedListener

override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.nav_layout)
setSupportActionBar(toolbar)

val toggle = ActionBarDrawerToggle(
this, drawer_layout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close
)
drawer_layout.addDrawerListener(toggle)
toggle.syncState()

nav_view.setNavigationItemSelectedListener(this)


override fun onBackPressed()
if (drawer_layout.isDrawerOpen(GravityCompat.START))
drawer_layout.closeDrawer(GravityCompat.START)
else
super.onBackPressed()



override fun onNavigationItemSelected(item: MenuItem): Boolean
// Handle navigation view item clicks here.
when (item.itemId)
//Handle selected item


drawer_layout.closeDrawer(GravityCompat.START)
return true




The belonging layoutfile:



<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="start"
tools:openDrawer="start">

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:context=".NavigationDrawerActivity">

<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>

</android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView

android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"/>

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


Now when I create an activity extending the navigation the content of the layout of the activity (activity_main) isn't shown.



class MainActivity : NavigationDrawerActivity() 

override fun onCreate(savedInstanceState: Bundle?)
setContentView(R.layout.activity_main)
super.onCreate(savedInstanceState)





Maybe it's because of the order of the two statements in the MainActivity:



 setContentView(R.layout.activity_main)
super.onCreate(savedInstanceState)


But if I change the order I can see my content, but not the Navigation.



Does anybody know my error?










share|improve this question























  • It's impossible to do it like that. You can't setContentView() twice and get merge effect
    – Stanislav Bondar
    Nov 12 at 12:19










  • So it's wrong to have this call in both activities right? Do you know how I can change my code? Is the only way to work with fragments?
    – Sabi
    Nov 12 at 13:17










  • So I guess I have to include a FrameLayout to my layout file. Can anybody tell me how to work with that without using fragments?
    – Sabi
    Nov 13 at 9:40













0












0








0







I try to get a navigation drawer that can be used for every activity (in kotlin). Unfortunately the content of the activities isn't shown if I extend the NavigationDrawerActivity. I know there are a lot of questions about this topic but the already given answers couldn't fix my problem.



I toke the most from the Android Studio Navigation layout so my NavigationDrawerActivity looks like this:



abstract class NavigationDrawerActivity : AppCompatActivity(), 
NavigationView.OnNavigationItemSelectedListener

override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.nav_layout)
setSupportActionBar(toolbar)

val toggle = ActionBarDrawerToggle(
this, drawer_layout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close
)
drawer_layout.addDrawerListener(toggle)
toggle.syncState()

nav_view.setNavigationItemSelectedListener(this)


override fun onBackPressed()
if (drawer_layout.isDrawerOpen(GravityCompat.START))
drawer_layout.closeDrawer(GravityCompat.START)
else
super.onBackPressed()



override fun onNavigationItemSelected(item: MenuItem): Boolean
// Handle navigation view item clicks here.
when (item.itemId)
//Handle selected item


drawer_layout.closeDrawer(GravityCompat.START)
return true




The belonging layoutfile:



<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="start"
tools:openDrawer="start">

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:context=".NavigationDrawerActivity">

<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>

</android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView

android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"/>

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


Now when I create an activity extending the navigation the content of the layout of the activity (activity_main) isn't shown.



class MainActivity : NavigationDrawerActivity() 

override fun onCreate(savedInstanceState: Bundle?)
setContentView(R.layout.activity_main)
super.onCreate(savedInstanceState)





Maybe it's because of the order of the two statements in the MainActivity:



 setContentView(R.layout.activity_main)
super.onCreate(savedInstanceState)


But if I change the order I can see my content, but not the Navigation.



Does anybody know my error?










share|improve this question















I try to get a navigation drawer that can be used for every activity (in kotlin). Unfortunately the content of the activities isn't shown if I extend the NavigationDrawerActivity. I know there are a lot of questions about this topic but the already given answers couldn't fix my problem.



I toke the most from the Android Studio Navigation layout so my NavigationDrawerActivity looks like this:



abstract class NavigationDrawerActivity : AppCompatActivity(), 
NavigationView.OnNavigationItemSelectedListener

override fun onCreate(savedInstanceState: Bundle?)
super.onCreate(savedInstanceState)
setContentView(R.layout.nav_layout)
setSupportActionBar(toolbar)

val toggle = ActionBarDrawerToggle(
this, drawer_layout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close
)
drawer_layout.addDrawerListener(toggle)
toggle.syncState()

nav_view.setNavigationItemSelectedListener(this)


override fun onBackPressed()
if (drawer_layout.isDrawerOpen(GravityCompat.START))
drawer_layout.closeDrawer(GravityCompat.START)
else
super.onBackPressed()



override fun onNavigationItemSelected(item: MenuItem): Boolean
// Handle navigation view item clicks here.
when (item.itemId)
//Handle selected item


drawer_layout.closeDrawer(GravityCompat.START)
return true




The belonging layoutfile:



<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="start"
tools:openDrawer="start">

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
tools:context=".NavigationDrawerActivity">

<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>

</android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView

android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"/>

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


Now when I create an activity extending the navigation the content of the layout of the activity (activity_main) isn't shown.



class MainActivity : NavigationDrawerActivity() 

override fun onCreate(savedInstanceState: Bundle?)
setContentView(R.layout.activity_main)
super.onCreate(savedInstanceState)





Maybe it's because of the order of the two statements in the MainActivity:



 setContentView(R.layout.activity_main)
super.onCreate(savedInstanceState)


But if I change the order I can see my content, but not the Navigation.



Does anybody know my error?







android android-layout navigation-drawer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 13:42









Fantômas

32.3k156288




32.3k156288










asked Nov 12 at 12:14









Sabi

11




11











  • It's impossible to do it like that. You can't setContentView() twice and get merge effect
    – Stanislav Bondar
    Nov 12 at 12:19










  • So it's wrong to have this call in both activities right? Do you know how I can change my code? Is the only way to work with fragments?
    – Sabi
    Nov 12 at 13:17










  • So I guess I have to include a FrameLayout to my layout file. Can anybody tell me how to work with that without using fragments?
    – Sabi
    Nov 13 at 9:40
















  • It's impossible to do it like that. You can't setContentView() twice and get merge effect
    – Stanislav Bondar
    Nov 12 at 12:19










  • So it's wrong to have this call in both activities right? Do you know how I can change my code? Is the only way to work with fragments?
    – Sabi
    Nov 12 at 13:17










  • So I guess I have to include a FrameLayout to my layout file. Can anybody tell me how to work with that without using fragments?
    – Sabi
    Nov 13 at 9:40















It's impossible to do it like that. You can't setContentView() twice and get merge effect
– Stanislav Bondar
Nov 12 at 12:19




It's impossible to do it like that. You can't setContentView() twice and get merge effect
– Stanislav Bondar
Nov 12 at 12:19












So it's wrong to have this call in both activities right? Do you know how I can change my code? Is the only way to work with fragments?
– Sabi
Nov 12 at 13:17




So it's wrong to have this call in both activities right? Do you know how I can change my code? Is the only way to work with fragments?
– Sabi
Nov 12 at 13:17












So I guess I have to include a FrameLayout to my layout file. Can anybody tell me how to work with that without using fragments?
– Sabi
Nov 13 at 9:40




So I guess I have to include a FrameLayout to my layout file. Can anybody tell me how to work with that without using fragments?
– Sabi
Nov 13 at 9:40

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261983%2fnavigation-drawer-hide-the-content-of-the-extending-activities%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261983%2fnavigation-drawer-hide-the-content-of-the-extending-activities%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto