How can I change the App Bar titles in "Android Studio"? - android

I am pretty new to Android Studio and that might even be a dumb question but I didn't find anything for it on the Internet and I am looking for more than 5 hours now...
The important thing to mention is that I am using the prebuilt "Navigation Drawer Activity" on Android Studio, to which I'm new.
I don't even know which file is causing it to be called "home" I didn't find it, but if you know pls let me know so I will add the code of that file
app_bar_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimaryDark"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="#layout/content_main" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
I also want to change:
Thanks for your help :)

In the res/values/strings.xml, you can by editing these values:
<string name="menu_home">Home</string>
<string name="menu_gallery">Gallery</string>
<string name="menu_slideshow">Slideshow</string>

You can change it in your strings.xml file
res/values/strings.xml

Related

ViewPager problems

I set ViewPager's height wrap_content but it doesn't work. I tried answers in other similar questions but they didn't solve my problem. my activity_main code is this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C49A1544"
tools:context=".MainActivity">
<include layout="#layout/toolbar"
android:id="#+id/main_toolbar"/>
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewpager"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/standard_margin_x2"
android:layout_below="#id/main_toolbar"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" />
</RelativeLayout>
and I have 3 fragment layouts. really sorry for my low English, I am a beginner in Android app development please help me.
I found a solution myself. If we use UltraViewPager library instead of the default, the problem will be solved, but this library has bugs. Anyway, thank you for trying to help me with your comments.

incompatible types: AppBarMainBinding cannot be converted to View failure to complile

I have a nested included layouts in which i try to pass data binding.
the following code fails with the following error;
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/appBarMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.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" />
</com.google.android.material.appbar.AppBarLayout>
<include
layout="#layout/content_main"
android:id="#+id/contentMain"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
/.../ap_generated_sources/debug/out/com/example/.../databinding/ActivityMainBindingImpl.java:35: error: incompatible types: AppBarMainBinding cannot be converted to View
, (com.example...databinding.AppBarMainBinding) bindings[1]
^
if I remove the layout, the code compiles but then app:params added to include wont work. What am I missing? how to fix? Thanks
I had the same issue, and it was resolved after deleting the build folder in app directory and it built again without any error.
The problem is that the "content_main" layout not include flag or any layout inside it. Add it and make rebuild you that will fix the issue.

How put and call toolbar_main.xml in Content_main.xml?

I am new in android and have several questions, and decided to ask them here, hope you help me, thank you in advance.
First i have problems with when i make a new project i chose make activity with navigation drawers, in default the android studio make app_bar_main.xml , toolbar_main.xml and content_main.xml and involve content_main.xml in app_bar_main.xml so it makes i have toolbar in each of pages, but i want to put the toolbar (app_bar_main.xml) in content_main.xml but when i do it my app force close and appear lots of errors, any body have he right answer with sample code?
The reason for doing this is to customize my content specially when i use a dialog with out toolbar title, i search and test lots of sample code but none of them works in this case, I select "no title" in app-theme in dialog.xml but the dialog shows with empty place of toolbar title.
Thanks for your negative score instead of helping
.
app_bar_main.xml
<android.support.design.widget.CoordinatorLayout ....>
<include layout="#layout/toolbar_main" />
</android.support.design.widget.CoordinatorLayout>
.
toolbar_main.xml
<LinearLayout .....>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="right"
android:background="#color/colorPrimary">
<TextView
android:id="#+id/toolbarTitle" ... />
<ImageView
android:id="#+id/imageView"... />
</android.support.v7.widget.Toolbar>
//content
<include layout="#layout/content_main" />
</LinearLayout>
.
content_main.xml
<RelativeLayout
......
android:id="#+id/mainContent"
tools:showIn="#layout/app_bar_main">
</RelativeLayout>
You can use include tag <include layout="#layout/app_bar_main"/> in main_content.xml to include toolbar in main_content.xml

databinding must include a layout file

I have following very simple layout and wanted to switch to using data binding. Now I'm getting following error in my controller_main.xml:
Error:Execution failed for task ':app:dataBindingProcessLayoutsDebug_pro'.
****/ data binding error ****msg:[44 68 44 68 25] must include a layout
file:...\app\src\main\res\layout\controller_main.xml
****\ data binding error ****
Any ideas? The error says, the resource android:layout id in the include tag is missing (that's my interpretation of the error), but that's not true. Commenting out the include tag removes the error.
Does anyone see the problem?
controller_main.xml
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" >
<android.support.design.widget.CoordinatorLayout
android:id="#+id/coordinatorLayout"
android:fitsSystemWindows="true"
android:background="?attr/main_background_color"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/rlContent"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
<include
android:layout_width="fill_parent"
android:layout_height="#dimen/tool_bar_top_padding"
android:id="#+id/stub_view_main_header_fixed"
android:layout="#layout/view_main_header_fixed"
app:elevation="0dp"/>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
</layout>
view_main_header_fixed.xml
<?xml version="1.0" encoding="utf-8"?>
<View
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/vStatusbarBackground"
android:layout_width="match_parent"
android:layout_height="#dimen/tool_bar_top_padding" />
You should use layout instead of android:layout:
<include
android:layout_width="fill_parent"
android:layout_height="#dimen/tool_bar_top_padding"
android:id="#+id/stub_view_main_header_fixed"
layout="#layout/view_main_header_fixed"
app:elevation="0dp"/>
I had the exact same error, but for a different reason.
I was using <include> opening tag and </include> closing tag instead of <include for opening and /> for closing. It's little strange, but anyway your question helped me find my mistake. Thanks.

Spinner in Toolbar Example in Xamarin for Android

I am trying to implement a spinner in the toolbar of my navigation drawer.
My initial toolbar layout included the following xml code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/languagetoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light" >
<Spinner
android:id="#+id/toolbar_languageSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/array_languageSelect"
android:gravity="right" />
</android.support.v7.widget.Toolbar>
The thing is that there does not seem to exist to be an example that seem to show the implementation method using Xamarin. I have tried to use the following resources :
https://dabx.io/2015/01/02/material-design-spinner-toolbar-style-fix/ &
http://android-pratap.blogspot.co.za/2015/01/spinner-in-toolbar-example-in-android.html
x
The short comings of the two examples is that using Xamarin I have found that I cannot use .setAdapter as it only exists as an interface
The look that i want in the tool bar is similar to the image in the first link but having the spinner to the extreme right.
The solution that I finally found is explained perfectly by prathap in http://android-pratap.blogspot.co.za/2015/01/spinner-in-toolbar-example-in-android.html. The solution involves adding the spinner to the toolbar layout like below:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/languagetoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<Spinner
android:id="#+id/toolbar_languageSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="#array/array_languageSelect"
style="#style/MyTheme"
android:gravity="right" />
</android.support.v7.widget.Toolbar>
Then the code that follows will require the user to populate the spinner in the code from their activity.

Categories

Resources