Inflate menu does not work on custom toolbars - android-studio

i am having a problem with my menu, i made a custom toolbar using (androidx.appcompat.widget.Toolbar), and if i try to inflate my menu on that custom toolbar it simply won't show like on the android studio basic toolbar.
This is the kotlin code.
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
val tooltop = findViewById<Toolbar>(R.id.testol) as Toolbar
tooltop.inflateMenu(R.menu.menu)
return true;//super.onCreateOptionsMenu(menu)
}
And this is the custom toolbar code in the xml file
android:id="#+id/testol"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="-71dp"></androidx.appcompat.widget.Toolbar>
enter image description here

Related

Parse String on Button Click to Activity

I want to parse a String (link) to another activity, when a button in a ListView is clicked.
The ListView ist populated by JSON (fetched MySQL-Data).
What's the trick to send the 'link' to the other activity, when I press a button in the ListView?
So far I tried searching for XML Form submit... but I think this is not the right way, I think to much in the direction of programming html forms...
my ListView (populated dynamically)
<TextView
android:id="#+id/link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="82dp"
android:layout_marginLeft="82dp"
android:layout_marginTop="33dp"
android:textSize="18dp"
android:text=""
android:textColor="#color/colorAccent"
android:textStyle="bold"
android:visibility="invisible"/>
<android.support.v7.widget.AppCompatImageButton
android:id="#+id/videobutton"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_gravity="start"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:background="#drawable/cerclebackgroundpurple"
android:padding="10dp"
android:src="#drawable/ic_play"
android:tint="#color/colorPrimary" />
What I now want to do is to get the populated 'link' from the TextView in my new activity.
May be you are clicking a list item and navigate to another activity with required String(link) as you explained. For this purpose, try this.
On list item click, call activity intent like
Intent i=new Intent(CurrentActivity.this,NextActivity.class);
i.putExtra("link","PUT YOUR LINK HERE");
startActivity(i);

android app side menu like google map menu

I am looking to put side menu similar to "google map" side menu which appears next to "Search Google Maps" you click on the icon and you get menu
is there any framework to implement ?
spending much time but can't find out how
can any expert advise/suggest/help me
I would appreciate your help very much
What you are looking for is navigation menu with layout_gravity="start".
Declare your layout like as shown below:
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer_layout"
tools:context=".MyActivity">
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/navigation_view"
android:layout_gravity="start">
//put your menu items here...
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
If u want to see the hamburger icon as well then use the code below:
actionBarDrawerToggle=new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close);
drawerLayout.setDrawerListener(actionBarDrawerToggle);
and override onPostCreate as:
#Override
protected void onPostCreate(Bundle savedInstanceState){
super.onPostCreate(savedInstanceState);
actionBarDrawerToggle.syncState();
}
Let me know if this is not enough for you...

TextView in ToolBar moving to right on setDisplayHomeAsUpEnabled(true)

I am new to Android app development and using Android studio. I want to place a Textview in ToolBar. Here is my code of ToolBar xml file:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF5722"
android:elevation="4dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Holler"
android:textColor="#android:color/white"
android:textStyle="bold|italic"
android:textSize="30dp"
android:layout_gravity="center"
android:id="#+id/toolbar_title"
android:gravity="center"
/>
</android.support.v7.widget.Toolbar>
On my first activity it is showing as expected in centre. But when I launch new Activity the TextView is moving to bit right. Here is my code for FirstActivity:
toolbarHome = (Toolbar) findViewById(R.id.tool_bar_home); // Attaching the layout to the toolbar object
setSupportActionBar(toolbarHome);
final android.support.v7.app.ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setHomeAsUpIndicator(R.mipmap.ic_launcher);
actionBar.setDisplayHomeAsUpEnabled(true);
}
Please let me know if you require more code.
It is the default behaviour of toolbar. It is because of the margins of the back button. If it is a simple text, you can use the toolbar title to set a textview.
But if you want to use your textview in the toolbar. You want to hide the back button by calling :
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
Now you have to create your own back button by setting a ImageButton/ImageView with back arrow icon in the layout file along with your TextView to achieve the desired results.

Android: Spinner dropdown arrow goes out of the box

I'm trying to use a spinner view element in my android application, but the dropdown arrow always goes out of the element box.
Code from layout file:
<Spinner
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="#+id/spinner1"
android:layout_toRightOf="#+id/text1"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:spinnerMode="dropdown" />
And Here is the cropped output:
I dont use any mode.
May be that is the problem.

Is there any sliding menu with visible column before click?

I've searched but no result.
I would like have menu where you see still column and when you click on it, it will slide right or left showing the rest of layout. What is more it should slide over my activity.
Any help?
I'm looking for something like that:
I found sliding menu from jfeinstein only but when you swipe, your screen is moving also.
Thanks in advance.
This is probably what you need.
Example:
activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<shared.ui.actionscontentview.ActionsContentView
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:actions_layout="#layout/actions"
app:actions_spacing="50dp"
app:content_layout="#layout/content"
app:shadow_drawable="#drawable/shadow"
app:shadow_width="8dip"
app:spacing="64dip"
app:spacing_type="right_offset" />
</RelativeLayout>
app:actions_layout="#layout/actions" - this is the layout for your left side menu. You can put there everything you want
app:actions_spacing - offset from left side in dp - that means how much the left menu will be visible
app:content_layout="#layout/content" - this is the layout for main content. You can also put there everything. For example there you can have a FrameLayout and you can attach a fragment from code based on what menu item a user clicked
app:spacing_type="right_offset" and app:spacing="64dip" - that means that when left menu is opened, then how much the main content will be visible
MainActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState)
{
setContentView(R.layout.activity_main);
mSlidingMenu = (ActionsContentView) findViewById(R.id.content);
//this will open menu
mSlidingMenu.showActions();
//this will close menu
mSlidingMenu.showContent();
}

Resources