Control Text Size on Android Bottom Navigation View in android < 9 - xamarin.forms

we have a few apps where we support android from Version 6 min to 10.
Now I have a bottom Navigation bar (tabbedpage) 5 tabs and when tapping on it , the title gets cut off.
In android 9 I have implemented as recommended https://montemagno.com/control-text-size-on-android-bottom-navigation/
and works ,but it does not work on android 7 as it clearly says "android 9"
<resources xmlns:tools="http://schemas.android.com/tools">
<dimen name="design_bottom_navigation_text_size" tools:override="true">10sp</dimen>
<dimen name="design_bottom_navigation_active_text_size" tools:override="true">12sp</dimen>
</resources>
Can the size of the text be changed on android 7 and how? I am using the latest xamarin.forms

You could set the font size in code behind .
in Resource-> Menu
define the tab item
<menu 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">
<item
android:id="#+id/action_settings_1"
android:orderInCategory="100"
android:title="111"
app:showAsAction="never" />
<item
android:id="#+id/action_settings_2"
android:orderInCategory="100"
android:title="222"
app:showAsAction="never" />
<item
android:id="#+id/action_settings_3"
android:orderInCategory="100"
android:title="333"
app:showAsAction="never" />
</menu>
in Resource-> Layout
Add the following code in content_main.xml
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bottomNavigationView"
//... other property
app:menu="#menu/menu_main" />
in MainActivity
BottomNavigationView bottomNavigationView = FindViewById<BottomNavigationView>(Resource.Id.bottomNavigationView);
TextView textView = (TextView)bottomNavigationView.FindViewById(Resource.Id.action_settings).FindViewById(Resource.Id.largeLabel);
textView.TextSize=12;

Related

How to set the scroll property in the tabbedpage

I've created a tabbedpage to create a horizontal menu at the bottom of the page, but I can't set the scroll property.
This is my code:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="GET_SOUND.Views.MenuPage"
xmlns:local="clr-namespace:GET_SOUND.Views"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
android:TabbedPage.IsSmoothScrollEnabled="True"
BarBackgroundColor="{StaticResource Primary}"
SelectedTabColor="Orange"
UnselectedTabColor="#95FFFFFF">
<!--Pages can be added as references or inline-->
<local:Dashboard Title="Dashboard" Icon="dashboard" />
<local:Marchi Title="Marchi" Icon="marchi" />
<local:Isrc Title="Isrc" Icon="matrici" />
<local:Documenti Title="Documenti" Icon="documenti" />
<local:Documenti Title="Impostazioni" Icon="imp" />
<local:Anagrafica Title="Anagrafica" Icon="anagrafica" />
<local:OpereTutelate Title="Opere Tutelate" Icon="opere" />
I tried to insert -> App: tabmode = "Scrollable" and the assembly, as suggested in this question, but it gives me an error and I don't understand why
As a suggestion, you can try use
Shell Tab,As it says in documents:
When there are more than five tabs on a TabBar, a More tab will
appear, which can be used to access the additional tabs
And Xamarin.Community is also an option, you can set the scrollable tab on the bottom with TabStripPlacement="Bottom".you can see more in https://github.com/xamarin/XamarinCommunityToolkit/blob/main/samples/XCT.Sample/Pages/Views/TabView/ScrollTabsPage.xaml

How to Make a colored Notification Icon for my App

i got a PNG image and i want to make it my notification icon that appears on receiving any notifications i dont want it to be grey and white and idea how to achieve that ?
FB and youtube notifications icons are colored
My code
notificationBuilder.SetContentTitle("My-App")
.SetSmallIcon(Resource.Drawable.My_PNG_ICON)
.SetContentText(messageBody)
.SetAutoCancel(true)
.SetShowWhen(false)
.SetContentIntent(pendingIntent);
i used this link with my PNG image but it gives out a white and grey icons Link
On the notificationBuilder call chain, there should be a method called SetColor. Use that when trying to set notification title/icon color.
notificationBuilder.SetContentTitle("My-App")
.SetSmallIcon(Resource.Drawable.My_PNG_ICON)
.SetContentText(messageBody)
.SetAutoCancel(true)
.SetShowWhen(false)
.SetContentIntent(pendingIntent)
.SetColor(new Color().ToArgb()); // NEW LINE TO SET COLOR
You may need this line as well, but test to make sure
.SetColorized(true)
notificationBuilder.SetSmallIcon can not show the real color, you can custom a RemoteViews to use it for notificationBuilder. Then can show what your wants.
The sample code as follow:
RemoteViews contentViews = new RemoteViews(PackageName, Resource.Layout.custom_notification);
contentViews.SetImageViewResource(Resource.Id.icon, Resource.Drawable.heart_save);
contentViews.SetTextViewText(Resource.Id.tv_left, "Custom title");
contentViews.SetTextViewText(Resource.Id.tv_right, "Custom content");
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
Notification notification = notificationBuilder.SetOngoing(true)
.SetSmallIcon(Resource.Drawable.check)
.SetContentTitle("App is running in background")
.SetPriority(1)
.SetContent(contentViews) // here add custom RemoteViews
.SetCategory(Notification.CategoryService)
.Build();
StartForeground(Constants.SERVICE_RUNNING_NOTIFICATION_ID, notification);
custom_notification.xml in layout folder:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="vertical"
android:paddingStart="48dp"
android:paddingEnd="48dp">
<ImageView
android:id="#+id/icon"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentStart="true"
android:src="#android:drawable/ic_lock_idle_alarm" />
<TextView
android:id="#+id/tv_left"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center_vertical"
android:text="Left" />
<TextView
android:id="#+id/tv_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:gravity="center_vertical"
android:text="Right" />
</RelativeLayout>
The effect:

Display image from network in ARCore

I'm attempting to use Glide to fetch an image using HTTP and display it in AR using ARCore Sceneform. The layout file is working because the border described in it is being displayed, but the image itself is not being displayed or even fetched.
Here is my code:
View view = View.inflate(context, R.layout.test_view, null);
if (v == 2) {
//ImageView imageView = (ImageView) renderable.getView();
Glide.with(context)
.asDrawable()
.load("http://i.imgur.com/DvpvklR.png")
//.into(view);
.submit(-1,-1);
rendobject =
ViewRenderable.builder()
.setView(context, view)
.setVerticalAlignment(ViewRenderable.VerticalAlignment.BOTTOM)
//.setSizer(new FixedWidthViewSizer(0.2f))
.setSizer(new FixedHeightViewSizer(0.15f))
.build()
.thenAccept(renderable -> {
testViewRenderable = renderable;
});
Here is the layout file:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/planetInfoCard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/rounded_bg"
android:gravity="center"
android:orientation="vertical"
android:padding="4dp"
/>
Here are the network permission declarations in the Manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I don't know what I'm missing/doing incorrectly.
Edit:
Here is something I also tried, but nothing is displayed after successfully scanning the augmented image:
rendobject =
ViewRenderable.builder()
.setView(context, R.layout.test_view)
.setVerticalAlignment(ViewRenderable.VerticalAlignment.BOTTOM)
.setSizer(new FixedHeightViewSizer(0.1f))
.build()
.thenAccept(renderable -> {
testViewRenderable = renderable;
ImageView imageView = (ImageView) renderable.getView();
Picasso.get()
.load("http://i.imgur.com/DvpvklR.png")
.fit()
.centerInside()
.into(imageView);
I don't see that the Glide call and the view are connected in any way. You have to load the image into the ImageView.

How replace a navigation icon with a navigation title in xamarin forms

I trying to add a navigation title icon to my app in one of the page and the code that i have used is:
For iOS:
NavigationPage.SetTitleIcon(this, "icon.png");
For Android in the ToolBar.axml I have added a ImageView as shown below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<ImageView
android:id="#+id/titleicon"
android:src="#drawable/UstNameIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.Toolbar>
The issue is that, I want my Navigtion icon to get disabled in my next Page and put a title instead of icon.
For that, I tried
For iOS:
NavigationPage.SetTitleIcon(this, null);
NavigationPage.Title="Title";
For Android, How can i achieve the change of Navigation title?
In MainActivity.cs
[Activity (Label = "Todo.Android.Android", MainLauncher = true, Icon="#android:color/transparent")]
For Title, you can set Title property in xaml or c#
To change text you just simple need to find that element by id, and set up a title:
var toolbar =
FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); // it may be simplifed
SetSupportActionBar(toolbar);
toolbar.Title = "title";
And image is under toolbar.Logo, so you can just try:
toolbar.Logo = null;
If you have some data in resources which you want to put in, you can use also:
toolbar.SetTitle();
toolbar.SetLogo();

My ViewLabel under Nutiteq doesn't work fine

I can populate the view for my ViewLabel in Nutiteq but I can't set right text in the text views of this Layout .
My code is following
//Setting Popup Label if we click the area
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View labelView = inflater.inflate(R.layout.popup_field, null);
//In order to get a dynamic "redimensionable" Ballon aka ViewLabel
labelView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
labelView.layout(0, 0, labelView.getMeasuredWidth(), labelView.getMeasuredHeight());
//labelView.measure(400, 400);
//labelView.layout(100, 100, 400, 400);
Log.info("drawField:: Nach Label fieldLabel = new ViewLabel... ");
LinearLayout lLayout = (LinearLayout)labelView.findViewById(R.id.layout1);
lLayout.setBackgroundColor(Color.RED);
TextView farmNameTV = (TextView)labelView.findViewById(R.id.farmName);
TextView areaTV = (TextView)labelView.findViewById(R.id.area);
TextView statusTV = (TextView)labelView.findViewById(R.id.status);
farmNameTV.setTextColor(Color.BLACK);
farmNameTV.setText("Farm CacoCaCoca");
areaTV.setTextColor(Color.BLACK);
String areaString = "12.34"
areaTV.setText("Area "+areaString);
statusTV.setTextColor(Color.BLACK);
String statusString = "Status:::qwertzuiopasdfghjklyxcvbnm";
statusTV.setText(statusString);
*What you can see red is my inflated View.
R.layout.popup_field looks like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/farmName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/farmName"/>
<TextView
android:id="#+id/area"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/area"/>
<TextView
android:id="#+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/status"/>
where strings are
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Nutiteq3D</string>
<string name="area">Area</string>
<string name="status">Status</string>
<string name="farmName">Farm Name</string>
</resources>
Have anyone done this task already? Can anyone help me to find out my error(s)?
With MapView of google Api is easy but I develop this with Nutiteq and just pure Activities, so, NO fragments and to inflate we typically need a ViewGroup and this ViewGroup under G-Api would be MapView so inherits from ViewGroup but in Nutiteq is not like this, MapView of Nutiteq inherits of android.view and I can't casting, I can just assign as ViewGroup a null in the call of inflateas you can see.
So, people, I'd be very thankful for your help.
Kind Regards
Solved!
It didn't have to do with ViewLabel but the normal Android.View, I wanted to assign Text to TextView's after I declared my resizable View and therefore it didn't work fine.
So the solution is writing all of tv.setText above
labelView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
labelView.layout(0, 0, labelView.getMeasuredWidth(), labelView.getMeasuredHeight());

Resources