Which part of the code should I insert in every activity to show the navigation drawer in every activity - android-studio

I have an app that already show the navigation drawer in the activity_main.xml ... I do know about using fragments.What I want to do is to show the navigation drawer in every activity without using the fragments...Which part of the codes shoud I copy and paste in every layout to show navigation drawer in every page..Is there any code that I should add to the MainActivity.java or should I add codes to my drawer.xml?
Note: all fragments are put in one layout(drawer.xml)
Which part should I add or modify codes to show navigation drawer in every activity without using fragments?

Related

Adding Image button after Add button is clicked (Android Studio Java)

Is it possible in Android studio to produce an Image Button after I clicked a button like Add Button. If yes, how? I want to make an attendance app wherein if the user clicks Add Class an image button will appear
We have no idea of which layout of you are using as the parent. But, for the best results of my answer, linear layout is advised.
The thing you are trying to achieve is trying to create dynamic elements.
For this, you can create an instance of the ImageButton class and then add it to you layout. This can be dont as follows:
//inside onclick of the add button
ImageButton newView = new ImageButton(context);
parentView.addView(newView);
You can add customisations to the view before adding it to the view.

Switch from fragment to activity in android studio

I made an application where I integrated the tabbed activity. In the tabbed activity I put 3 fragments. Now in the 3rd fragment I put a button and I want when I click on the button it redirects me to a new activity I did. I used an intent as we usually do between activities but it doesn't work. Need help please
use getContext instade of Activity.this. use the below code in your button to redirect from fragment to activity
yourButton.setOnClickListener(view -> {
startActivity(new Intent(getContext(), Your_Activity.class));
});
If the problem is not solved yet, let me know with logcat error.

How to transform a fragment in a new activity in android?

I have this activity, with a list of tokens/options in it. As of right now, i have a button that, using intents, opens a new activity based on the item selected (basically: a text to modify the settings and add extra info).
Now, i would like to make the first activity to show, in the below half of the screen,a preview of the new activity, but with fewer/diferent options and less information.
I know how to do that using fragments, but i don't know how to approach the creation of the new activity.
Is there a way to merge them both, to pass the first fragment to the second activity, or do i need to completely code (and thus, modify) "twice"?
Is there a better aproach that lets me do that easily?
If considered you are inflating options in recycler view in the activity, add a frame layout in the same as a container for a fragment to preview the new activity. Set the visibility to gone for the frame layout and when an option is selected set the fragment and display it. For a nice animation use android:animateLayoutChanges="true"
in the options activity xml at the root view. Hope I helped happy coding :)

How to add an view on top on activity layout dynamically which automatically shifted the old view down

I am working on an App in which I have an icon on Action Bar.When I click on this Action Bar icon then an EditText should come on the top of layout(below Action Bar) and all of the other data on layout should shif down.I am using Relative Layout.
I know how we can dynamically add view in relative layout.But here I have to add item on top on layout, while there is also some view on top before clicking the icon.
Try the below if it works for you, this is what you'll need as per my understanding of your question.
EditText et = new EditText(this);
empty.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
et.setText("Dynamic EditText!");
et.setMinLines(1);
et.setMaxLines(3);
relativelayout.addView(et);
// assuming you already have your relative layout and the rest declared.

adding buttons dynamically in android

I'm new to android development and needs help here.I want to create a layout where buttons are added dynamically.In this the no of buttons to be added are decided on the fly.(at run time) i.e depending upon the number return by server i want to add buttons.below is the layout i want to create.Please suggest me suitable solution.I was trying creating this layout with table layout.Thank You
http://i.stack.imgur.com/tbrEq.jpg
Read in your array of buttons and initialize your empty layout (i.e. setContentView). Then, create your buttons using the ImageButton constructor and call .addView(btn) from the layout where you want to insert the button. Don't forget to set any layout parameters you need.

Resources