I am new to Android development however lately when I choose a 'Blank' activity I am getting some 'Included Layout' that I can not seem to get rid of. As shown below it adds a blue top border and a email picture at the bottom right.
I have made a few small apps before and have never had these before. Now I make a blank activity and I get these. I know I can click 'hide' however that only hides them in the layout in Android and not in the application. The application still has these annoying things.
The pink button is called FloatingActionButton. Just remove the three lines of code in your onCreate() creating it and it will be gone.
The blue top border is called ActionBar. Change the extended class from AppCompatActivity to just Activity and that will be gone too.
choose empty activity instead of blank activity when you create new project .
That comes from with blank Activity which it has two layouts(there are two xml layout in the res/layout) which the first one has a FloatingActionButton as default!
And if you need to delete the content, you should be able to remove include from main layout and then see what is going on on the refering layout called content_main.
Even though question is answered satisfactorily to the asker. I still feel there is room to have one more answer as below.
Yes, If one no need any-more of these default implementations; selecting "Empty Activity" over "Blank Activity" would give some edge of not messing up.
But, there is no harm to select "Blank Activity" design. It just supplies some default embedded codes(corresponds to pink floating action button as well as menu action bar) which appears the root of issue to asker. And it can be removed if not required any-more.
1. To remove floating button please follow the answer given at following link.
<a> http://stackoverflow.com/questions/34780393/how-to-remove-the-floating-action-button/34852617#34852617 </a>
2. To remove "menu action bar" please follow these steps as below :
-> Remove complete "AppBarLayout" tag and their elements from "activity_main (as default implementation)".
-> To make neat source code, need to remove two override methods [i.e. onCreateOptionsMenu(Menu menu) and onOptionsItemSelected(MenuItem item)] from "MainActivity (as default implementation)".
Hope it would provide some easiness in activity selection.
Cheers!
Related
I am new to writing Android apps, I have been using the internet and Android Studio to create an app for my club as a bit of fun and learn along the way. I have been watching videos, using tutorials and walkthroughs and I am getting to learn the basics.
However, I have got stuck. I used a drawer template from Android Studio and added the activities I needed and buttons on the main screen to the activities and they all worked fine, no overlapping. When I tried to link the drawer icons to the activities, rather than use the buttons on the main screen, they work, but the app (visually) puts the next activities content on top of the one before.
I cant find anything on the internet except something called backstacking, but that is described when the back arrow is used, my problem is to do with selecting an activity from the drawer menu. I have attached a picture to show what I mean. It gets worse the more menu items that are selected.
If anyone could help, it would be great!
If you are using XML root layout as a constraint layout maybe your constraints are missing. If you are using constraint layout set both top/bottom and left/right constraint.
If your constraints only top for example it is look good on desing but in device that dont know where to positioning left or right and automatically positioning 0 point to top.
When you click one any one menu item put the visibility of other images as gone like
visibility(View.GONE);
and the one selected to be visible
I know it should be in the style sheet area for this, but when I created a new Android app using Android Studio, it has a user logo and user information in a green box. This is what I want to edit.
First it should ask them to login if first time using the app.
But let's deal with one thing at a time, and first is me getting use to where Google puts things.
If you look at your layout activiy you will find a "NavigationView", there are 2 attributes there you need "header" and "menu".
You can see in this answer how.to get the views inside the "header" file: https://stackoverflow.com/a/33631797/4017501
There is another alternative. The "NavigationView" is a ViewGroup. So you can use it as such. Delete thee "header" and "menu" attribute and add the closing brackets as if were a ViewGroup:
<NavigationView></NavigationView>
Now you can simply put a fragment inside and then find every view and handle your logic from the fragment, is a more direct and customizable approach.
I developed two menu like in Facebook app.
One of them contains expandableListView.
UseCase:
I open the menu, then I open a section. Now, My translation is closed by the redrawn, So it hides my menu.
To open my menu, I apply translation and then remove it and use offsetLeftAndRight to keep it open:
mainlayout.clearAnimation();
mainlayout.offsetLeftAndRight(pxTranslateMenu);
I tried to create my own view to solve this problem. But I have the same result when my items go from GONE to VISIBLE. When items go from INVSIBLE to VISIBLE all is OK, but i have a wrong render (free space where my items are placed).
Is there anyway of doing what i want : Keeping my menu open after clicking on section?
Thanks.
I tried to use some other component to avoid Accordion.
But i have the same problem when an EditText take focus or when i select an item in an AlertDialog.
I just found a way to overpass this problem.
I just create a new activity wich has a translucent part.
In this way, i can do what i want.
I hope that i'm gonna be able to resolve all demand by this way.
I'm new into android and i'm dealing with the following problem. I need to create a button which groups another two buttons of similar features (sort of submenu). So let's say we have a button called "search", by clicking on it the search button should disappear and the two buttons (e.g. "google" and "bing") should be seen on the screen.
So, my idea was to manage all three buttons programmatically in the same layout instead of creating a new (temp)layout just to show and handle the two buttons. Like a state machine. More precisely it would be like this:
We press on the "search" button.
onClick(View) determines wheter we are on the main screen (mode=mainmenu), renames the search button to "google" and creates the second button named "bing", or (mode=submenu) then call the function of the button due to the search button is already renamed to "google"...
By pressing the back button onBackPressed() checks if we are in the submenu (mode=submenu) then hide the "bing" button and rename "google" to "search", otherwise we are in the main menu (mode=mainmenu), finish the activity.
Does this make sense at all? Besides this will produce lots of code with rising count of buttons and (sub)menus and worse maintainability for further changes.
Thanks!
P.S. Sorry if my english sucks (not my native language) ;-)
That's too much code and too much debugging will be needed, so I think, a better way is just creating a new layout.
Well if you have performance issues or expecting performance issues can arise (due to complexity of you GUI) then may be this make sense. But if not, code simplicity is more important than slight increase in performance.
You can create an button that remain invisible(gone, to be exact) until the "search" button is pressed, and rename the original search button. It works, and it will be easier to implement if you set up layout in xml. It also give you a preview that shows what it looks like. To show widget programmatically will have code that hard to maintain.
However, the design that change button text is not a good design. First, when the "search" is pressed, changing its text is very confusing. I personally suggest you to pop-out a selection dialog. Or just show both search button at first place, unless you really do not have place for two button.
I'm very new to android and I am wondering how I can have 2 windows displaying content at the same time.
Here is an example:
I have a HorizontalScrollView at the bottom of the screen which houses the buttons for a menu. Above it, I would like a window(like a JFrame) that I can change depending on which button from the menu was pressed. The ScrollView menu must remain unchanged an exist as a separate entity(if you know what I mean).
How can I go about doing this? I don't want to have to draw the menu every time a user click a button and a new page is displayed. I have a feeling it has something to do with intents and Activities, but I'm not sure.
Hope someone can help me out.
Thanks.
I'm very new to android and I am wondering how I can have 2 windows displaying content at the same time.
Interpreting you literally, you can't, but that's because "window" does not mean what you think it does.
Here is an example: I have a HorizontalScrollView at the bottom of the screen which houses the buttons for a menu.
Get rid of it and replace it with an options menu, so your application blends in with the platform.
Above it, I would like a window(like a JFrame) that I can change depending on which button from the menu was pressed. The ScrollView menu must remain unchanged an exist as a separate entity(if you know what I mean). How can I go about doing this?
Option #1: Get rid of the HorizontalScrollView, use an options menu, and use separate activities for each "window"
Option #2: Use a ViewFlipper, with one child of the ViewFlipper for each "window".
Of the two, Option #1 will generally be much better, for memory management, state management, code complexity, and UI design.
Could TabLayout be your answer :
http://developer.android.com/resources/tutorials/views/hello-tabwidget.html