So a noob question: I started a project with a navigation bar in Xamarin and I just want to change the default icons and change names under them in accordance with my app. Can I do that in the constructor view? The buttons themselves already do what I want them to do but I just want to change their appearance. pic activity_main.xml just in case:
<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/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/containerTwo"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
android:layout_alignParentBottom="true"
app:menu="#menu/navigation"
android:accessibilityHeading="true"
/>
</RelativeLayout>
</RelativeLayout>
Okay, I got it. What I managed to do:
Used this article
Installed Xamarin.Android.Support.Design
Downloaded desired icons from Asset Studio
Unpacked zip file with icons and placed all of the "drawable" folders in Resources\drawable
changed android:icon parameter in navigaton.xml to one of the downloaded icon names
NOTE: sometimes preview gets messed up, for example it might size icons in different scales but when you emulate the build or execute it on a real phone everything looks fine.
Related
I'm implementing a Navigation View on my activityHome for the first time. When i run the app and enter the home activity it function well. The problem is at the XML editor on the android studio, the Nav View is above all the other elements and doesn't let me click on them.
I haven't touch anything else but these yet.
Thanks.
XML CODE:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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:id="#+id/dl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:fitsSystemWindows="true"
tools:context=".activities.HomeActivity"
tools:openDrawer="start">
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/header"
android:background="#color/colorPrimary"
app:menu="#menu/menu"
tools:ignore="MissingConstraints" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/iv_menu"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="?android:selectableItemBackground"
android:scaleType="centerInside"
app:layout_constraintBottom_toTopOf="#+id/guideline46"
app:layout_constraintEnd_toStartOf="#+id/guideline139"
app:layout_constraintStart_toStartOf="#+id/guideline135"
app:layout_constraintTop_toTopOf="#+id/guideline45"
android:elevation="10dp"
app:srcCompat="#drawable/menubuttonofthreelines_79781" />
...
and continues with the other elements.
Your layout has nothing wrong..
The reason that Android Studio shows that the drawer layout in the Open state in the design view because you set tools:openDrawer="start" in the DrawerLayout .. if you want to see the main layout in the design mode (i.e. to make the drawer in the close state), then you need to remove this attribute.
This attribute won't affect the looking of your app when you launch it.
Documentation:
You can insert sample data in your layout preview by using the tools: prefix instead of android: with any attribute from the Android framework. This is useful when the attribute's value isn't populated until runtime but you want to see the effect beforehand, in the layout preview.
XML tools namespace is just used to show you some behavior on Android Studio, but not while you run the app. Please check documentation for more info
I am using https://github.com/roughike/BottomBar library to make my bottom bar
for android but i can't change the size of the icons , any idea how to make them small ?
activity_main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:app="http://schemas.android.com/apk/res-auto"
tools:context="ytstudios.wall.plus.MainActivity"
android:background="#color/colorAccent">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:elevation="8dp">
</android.support.v7.widget.Toolbar>
<com.roughike.bottombar.BottomBar
android:id="#+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
app:bb_tabXmlResource="#xml/bottom_tabs"
app:bb_inActiveTabColor="#color/tabSelected"
app:bb_inActiveTabAlpha="0.2"
app:bb_behavior="iconsOnly"
app:bb_activeTabColor="#color/tabSelected">
</com.roughike.bottombar.BottomBar>
The easiest way would be use Android Asset Studio tool to convert your icons according to your size
As you will reduce asset size in the tool your icon will be reduced in size and will be displayed correctly.
In my app I want to display a simple Image,
On my Samsung Galaxy S7 Real device the image is fine, The bottom Navigation bar is not part of the view but part of the phone itself.
The whole of the Image is present.
On the Android Emulator the bottom navigation bar is part of the view and the image is partially hidden
Here is my simple Linear Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#color/md_blue_50"
android:orientation="vertical">
<include
android:id="#+id/app_bar"
layout="#layout/toolbar"/>
<ImageView
android:id="#+id/photo_image_large"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:scaleType="fitXY"/>
</LinearLayout>
Here is the Android Emulator Screenshot
android emulator
Here is my Samsung Galaxy Real Device Screenshot
android real device
The problem also occurs in recycler Views in the app the bottom part of the image is cut off on the android emulator...
It's because of android:fitSystemWindows put it to false and it should be good
I had similar problems with BottomNavigationView (menu) this is solution :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_activity_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="#+id/main_activity_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
app:itemIconTint="#color/color_main_white"
app:itemTextColor="#color/color_main_white"
app:menu="#menu/bottom_navigation_menu"/>
Try to change parameter android:layout_heigh to 0dp and add this android:layout_weight="1" for ImageView
you have to place the view above the bottom navigation bar so that the view wont hide in the bottom navigation bar
The version of my constraint layout is 1.0.0-alpha8 . After I have included a toolbar in my layout , there is space in both left and right side of the toolbar, like the image below
Here is the code for my toolbar
<?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:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary">
</android.support.v7.widget.Toolbar>
Which I have included in my layout in following way
<include
layout="#layout/toolbar_top"
android:id="#+id/topPanel"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
I didn't used any additional padding or margin in my root element of the layout file .
Another stange thing is if I compile or build the program my code automatically changed, like
<include
layout="#layout/toolbar_top"
android:id="#+id/topPanel"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
Change to
<include
layout="#layout/toolbar_top"
android:id="#+id/topPanel"
android:layout_height="wrap_content"
android:layout_width="368dp"/>
And the guideline also add some additional value which I didn't write, like layout_editor_absoluteX automatically added .
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline1"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.15"
tools:layout_editor_absoluteX="58dp"/>
First, you should update to ConstraintLayout beta 4.
Now, the root problem you have is that you are using match_parent on the toolbar -- this isn't supported by ConstraintLayout. You need to add:
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
and use 0dp instead of match_parent:
<include
layout="#layout/toolbar_top"
android:id="#+id/topPanel"
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
Note that you can create those attributes easily by doing right-click on the component, and picking
On Android Studio 2.2 you need to hold the key to create the constraints, on Android Studio 2.3 it creates the constraints by default.
I am new to the Android and I am working on a partially completed Android project.
In all the screens of my app there is a header bar which has the logo of the app and the app name in the left. This header is automatically added to the newly created xml files too. But I want to remove the app icon from this header bar. When I look at my .xml file I don't find any reference to the logo or the app name. I suspect the header is defined globally somewhere in the project. How do I find that in my project so that I can edit it?
I want to remove the 'SD' image from the header. Here is my xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#drawable/bg_main"
tools:context=".AlbumFragment" >
<fragment
android:id="#+id/fragmentBook"
android:name="com.hcpt.course.fragment.BookFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="#+id/fragmentBookMark"
android:name="com.hcpt.course.fragment.BookMarkFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="#+id/fragmentSetting"
android:name="com.hcpt.course.fragment.SettingFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="#+id/fragmentAbout"
android:name="com.hcpt.course.fragment.AboutFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>