Layout preview not showing ActionBar overflow options - android

I'm having a slight issue here where the overflow options for the ActionBar are showing up in the emulator but not the layout preview. I'm currently using Android Studio v 2.1.3.
Has anyone else come across the same issue?
Layout Preview
Emulator Screenshot

In your layout file, add the tools:menu attribute directly to the Toolbar widget:
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
tools:menu="#menu/your_menu"/>
According to the docs:
tools:menu
Intended for: Any root <View>
This attribute specifies which menu the layout preview should show in
the app bar. The value can be one or more menu IDs, separated by
commas (without #menu/ or any such ID prefix and without the .xml
extension).
However, I find that it only works if:
the attribute is added directly to the Toolbar widget
the value includes the #menu/ prefix

Try to add a tools:menu to your root view in the layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:menu="menu1,menu2" />
more info here:
http://tools.android.com/tech-docs/tools-attributes

Related

Android studio navigation editor is not showing the fragment's attributes

I am using Navigation Editor in the android studio and my android studio version is 3.3.2.
my problem is when I add a fragment to the navigation editor, the attributes of the fragment are not showing in design mode. look at the picture:
mobile_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:tools="http://schemas.android.com/tools">
<fragment id="#+id/currentWeatherFragment2"
name="ir.houmansanati.forecastmvvm.ui.weather.current.CurrentWeatherFragment"
label="current_weather_fragment" tools:layout="#layout/current_weather_fragment"/>
<fragment id="#+id/futureListWeatherFragment4"
name="ir.houmansanati.forecastmvvm.ui.weather.future.list.FutureListWeatherFragment"
label="future_list_weather_fragment" tools:layout="#layout/future_list_weather_fragment"/>
<fragment id="#+id/futureDetailWeatherFragment2"
name="ir.houmansanati.forecastmvvm.ui.weather.future.detail.FutureDetailWeatherFragment"
label="future_detail_weather_fragment" tools:layout="#layout/future_detail_weather_fragment"/>
<fragment id="#+id/settingsFragment2" name="ir.houmansanati.forecastmvvm.ui.setting.SettingsFragment"
label="SettingsFragment"/>
</navigation>
as you see my fragments in XML have name and label and id attributes but all of them are labeled as fragment. even when I set the attributes from the design mode after pressing Enter the text is gone but it changes in XML text.
I have tried Invalidate Caches/Restart but the problem still exists.
Any help?
You're using id=, name=, and label=. As per the Implementing Navigation documentation, these need to be android:id=, android:name=, and android:label=, respectively.
Note that your topmost <navigation> element must also contain xmlns:android="http://schemas.android.com/apk/res/android" in order to use the android: prefix.

How to make namespace attr in XML code appear on the next line when reformatted

Every time I reformat my XML code, xmlns moves up to a line where root element's tag name is written.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
xmlns:android... is next to the CoordinatorLayout. I played with XML section of Code Style menu in AndroidStudio, but couldn't do it.
This is what I want to have when I reformat my layout XML file:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
Can someone help me with this?
This is the XML attribute arrangement in my AndroidStudio:
Go to File -> Settings -> Editor -> Code style -> XML.
There are 4 submenus (Tabs and Intents, Other, Arrangement, Android), select Android.
On the right side, below the Layout Files check both Insert line break before first attribure, Include namespace declarations.

How to minimize NavigationView / NavigationDrawer?

I'm trying to minimize or collapse the NavigationView / NavigationDrawer when my app is running on tablets.
The result I want is the one used by GMail app, see screenshot below (you can see the desired layout collapsed on the left).
Does exists any method or a pattern to follow to achieve this?
After reading carefully this official NavigationDrawer guidelines, I found that my question used wrong keywords : it is called mini navigation drawer (that's why I edited my question first).
So I was able to find an answer:
Use third party library, which is proposed in this answer (yes, my question is a duplicate!);
Develop your own solution, by following this sample; be aware that you have to add some fancy animation and other decoration in order to respect Material design guidelines.
Any way, the trick is to simply add a margin left to the detail view (FrameLayout in this case), like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Master fragment-->
<fragment
android:name=".MainFragment"
android:layout_width="220dp"
android:layout_height="match_parent"
android:id="#+id/fragment_master">
</fragment>
<!--Detail layout -->
<FrameLayout
android:layout_width="1000dp"
android:layout_height="match_parent"
android:layout_marginLeft="56dp">
</FrameLayout>
</android.support.v4.widget.SlidingPaneLayout>

How do I use DrawerLayout to display over the ActionBar/Toolbar and under the status bar on KitKat?

I've problems with implementing this guidelines in Kitkat. On Lollipop everything looks ok:
But on Kitkat Toolbar does not have any top padding:
I can fix this with https://github.com/jgilfelt/SystemBarTint library using:
SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
mainView.setPadding(0, config.getPixelInsetTop(false), config.getPixelInsetRight(), config.getPixelInsetBottom());
But I feel that I'm doing something wrong. Do you have any good practices how to achieve this effect on KitKat?
Move current layout resource in layout-v21 folder to have it as it is on the first screenshot. Then try to create new layout resource that will have just a placeholder view of same height of the status bar
Hierarchy should be following:
--Top layout
--<view layout_height="25dip"...>
-- Toolbar
-- the rest of the views
Using view аbove your Toolbar, will not push it behind the status bar, as it is on second screenshot and will mimick the padding you are trying to achieve
Do you have fitsSystemWindow set to true? Setting it to false will bring the toolbar back under the status bar.
The effect you see for Kitkat is because you have translucent status bar set and fitting to System Window goes underneath it.
For example, in your layout XML file:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:fitsSystemWindows="false">
<android.support.v7.widget.Toolbar
android:background="#color/blue"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:id="#+id/action_bar"/>
<!-- YOUR CONTENT HERE -->
<!-- YOUR NAVIGATION VIEW HERE -->
</android.support.v4.widget.DrawerLayout>

Eclipse Content Assist Not Working Properly For Android Layout

Whenever I have Views inside a ViewGroup inside a android.support.v4.widget.DrawerLayout, Eclipse's autocomplete starts working weird. It doesn't display most of the properties
Example with DrawerLayout -> LinearLayout -> ImageView:
In the previous screenshot, you can see that I typed "android:scale..." and the IDE's intellisense isn't showing me the ImageView's android:scaleType
If I use Eclipse's Properties window for the ImageView, I can see that it is only displaying the basic properties for "View" (and not for ImageView...):
Now if the ImageView is not a descendant of the DrawerLayout and I put it somewhere else, the autocomplete works properly:
I've seen related questions such as:
Autocomplete does not work in XML files in particular hierarchy
Content Assist doesn't work in xml with support library
but they have been dead with no answers for quite a while...
Content assist doesn't work for Views (be it TextViews, EditText, Buttons...) that I add inside the DrawerLayout. It only suggests the 'basic' properties.
Does anybody know why this happens or how to fix this?
Sample layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/some_image" />
</LinearLayout>
<RelativeLayout
android:id="#+id/drawer_view"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start" >
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
Just to give some closure to this 5 months-old question, I'll quote and link to Atul O Holic's answer. Thanks to Dileep Perla for pointing me there.
When using support package Widgets this is a common scenario (a weird
one too).
Here you using, android.support.v4.widget.DrawerLayout and hence the
issue. Happened with me a lot of time.
You can also try couple of options mentioned here.
I've found that using the tag can be handy in this case. Just put your layout that is inside the drawer in a separate layout file and then include it inside the drawer layout.

Categories

Resources