A bit of context:
I was looking into the Material Design Support Library for Xamarin and found this article about various controls from this library.
I tried to reproduce the Toolbar from the last example (for now I'm not even thinking about implementing the whole hamburger navigation example, just the toolbar with the button). I set it up, created MyTheme with my colors, added the fixes for style-v21 and so on. Everything works well so far, though the <include ... /> node throws a warning that it's not a recognized child for RelativeLayout. Still, it's building correctly so I can deal with it for the most part.
The problem:
Here's where my problem starts:
...
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.main_layout);
var toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
SetSupportActionBar (toolbar);
//Enable support action bar to display hamburger
SupportActionBar.SetHomeAsUpIndicator (Resource.Drawable.ic_menu);
SupportActionBar.SetDisplayHomeAsUpEnabled (true);
...
With the SupportActionBar set up like that, it doesn't display the button. Also, the ic_menu drawable seems to be missing. In fact, there aren't any that start with ic_, only abc_.
Am I missing something here?
Cheers!
Go to https://material.io/icons/ and download menu icon and then add that icon to the drawable folder and then replace ic_menu in your code with the image name.
NOTE: Do not add image extension name like .jpg,.png with image name
Related
I am developing an app on Visual Studio for Mac with Xcode. I have a Window Controller with Sidebar that gives you a split view controller that is split into a sidebar controller and a view controller.
Right now it looks like this:
Split View Controller
I want to be able to toggle the left sidebar (as in collapse or show) when I click on the sidebar icon in the toolbar. I added the icons in the toolbar as Custom Toolbar Items by just dragging and dropping a textured round button and putting an icon in it.
Does anyone have an idea as to how to do this? is there a function already that I need to call? would greatly appreciate it.
So far, I found online some resources like the following:
https://developer.apple.com/forums/thread/705335
However they are all in Swift and I could not find any equivalents for C#.
from the docs
Optionally, you can show and hide the Master View Controller using the
PreferredDisplayMode property of the Split View Controller
I found a very simple way to do it if you are using storyboards on Xcode.
1.) Select the First Responder in the Interface Hierarchy
2.) Scroll down in the Connection Inspector, and you will see the definition of the toggleSidebar: action.
3.) Click on the + icon on the right of the action and drag it to the Sidebar button on your Document outline (under toolbar).
you now connected the built-in toggleSidebar action to the sidebar toolbar item.
I have created android app using xamarin native and put some pics in res/drawable but when I want to use that images in xml they don't show up neither in designer view nor in intellisense.
<EditText
android:layout_width="333dp"
android:layout_height="156dp"
**android:background="#drawable/emailbg"**
android:hint="Password"
android:password="true"
android:textSize="20dp"
android:layout_marginTop="280dp"
android:paddingStart="100dp"
android:paddingBottom="25dp"
android:textColorHint="#a3a3a3"
android:id="#+id/pass_et"
/>
Please mark sure that you are putting the image under drawable folder and the Build Action is AndroidResource.
If the image does not show up, try to close Visual-Studio and open again.
Here is a screenshot I did and it works well on my side. Feel free to ask me any question.
I am currently working on MVVMCross Xamarin Android project. So far I have achieved normal navigation and bottom bar navigation. I want to open dynamic fragments inside each bottom bar tabs. e.g I have bottom bars menus Recent, Favorite and NearBy. Clicking on each tab it create fragments. Inside each fragment I want to provide facility to dynamically create fragments on click.
I want to achieve here is, it should keep stack of navigation tab wise. Let say I created 5,3,4 fragments respectively for Recent, Favorite and Nearby and currently I am on favorite tab and clicking on back should first navigate back to all 3 tabs. Like wise it should follow navigation for other tabs.
Exact same feature and functionality available in this github link
[https://github.com/ncapdevi/FragNav][1]. This is one is for Android but I need advice how can I achieve same functionality with Xamarin, MVVMCross and C#.
Any help greatly appreciated.
First your link is dead,and then i think you need to understand the back stack of fragments and show hidden features to implement that.FragmentTransaction
general train of thought, you have RecentFragment, FavoriteFragment and NearByFragment three root fragments,
when you click the relative tab ,you can use show and hide method of fragment like
this :
FragmentTransaction fTransaction = FragmentManager.BeginTransaction();
hideAllFragment(fTransaction);
//judge which tab is clicked
switch (tab.Id)
{
case Recent:
if (recentFragment== null)
{
recentFragment= new RecentFragment ();
fTransaction.Add(Resource.Id.ly_content, recentFragment);
}
else{fTransaction.Show(recentFragment);}break;
case Favorite:
if (favoriteFragment== null)
{
favoriteFragment= new FavoriteFragment();
fTransaction.Add(Resource.Id.ly_content, favoriteFragment);
}
else{fTransaction.Show(favoriteFragment);}
break;
case NearBy:
if (nearByFragment== null)
{
nearByFragment= new NearByFragment();
fTransaction.Add(Resource.Id.ly_content, nearByFragment);
}else{fTransaction.Show(nearByFragment);}break;
}
fTransaction.Commit();
and then in each root fragment to implement the back stack use addToBackStack :
FragmentManager fragmentManager = FragmentManager;
FragmentTransaction fragmentTransaction = fragmentManager.BeginTransaction();
fragmentTransaction.Replace(containerViewId,fragment);
fragmentTransaction.AddToBackStack(null);
fragmentTransaction.Commit();
at last you could try to encapsulating a controller
When creating an Extension for Visual Studio 2013 a tool window gets set up by default. However, I'd like to have a second tool window and can't see how one is supposed to go about that.
I have created a guide:
HOWTO: Create a toolwindow with a ToolWindowPane class in a Visual Studio package
http://www.visualstudioextensibility.com/2015/02/20/mz-tools-articles-series-howto-create-a-toolwindow-with-a-toolwindowpane-class-in-a-visual-studio-package/
Well I just found a few things - so I'm gonna answer my own question so that other people having the same problem may take advantage of it:
Set up your extension as in this tutorial but check "Tool Window"
Create a new UserControl for the ToolWindow "ToolWindow2Control" and copy paste the contents of ToolWindowControl.xaml & ToolWindowControl.xaml.cs accordingly
Add a class "ToolWindow2" and copy paste the contents from ToolWindow.cs. Change the GUID to a new one (Tools->Create GUID)
In NameOfYourProject.vsct add the code for displaying a second entry in View->Other Windows by duplicating the Button found in the Buttons section. Change the ButtonText, the priority, the id of the Button and the id of the Icon.
Add the id of the Button to the entries under Symbols on the bottom of the page. It should be a third entry under guidNameOfYourProjectCmdSet.
Open PkgCmdID.cs (or PkgCmdIDList.cs) and add the id of the Button there as well, e.g.
public const uint cmdidMyTool2 = 0x102;
Add another icon to your project / resources. Then add another Bitmap entry in the Bitmaps section of NameOfYourProject.vsct with the GUID-id that you previously gave the Icon. Like so:
<Bitmap guid="guidImages2" href="Images\test.ico" usedList="testIcon"/>
And create another GuidSymbol entry in the Symbols section with a new GUID and a single IDSymbol entry which has the same name as the one you used in the usedList, like so:
<GuidSymbol name="guidImages2" value="{7BC1F97F-2693-4186-91CC-A35AE95886CE}" >
<IDSymbol name="testIcon" value="1" />
</GuidSymbol>
Add this line to NameOfYourProjectPackage.cs:
[ProvideToolWindow(typeof(ToolWindow2))]
In NameOfYourProjectPackage.cs edit the Initialize method by copy-pasting the 3 lines under // Create the command for the tool window beneath it. In the first line use the id we gave in step #6 (cmdidMyTool2). In the 2nd line use a new MenuCommand Event handler ShowToolWindow2. And change the variable names.
Create a new method ShowToolWindow2. Copy paste from the ShowToolWindow method and change the typeof in the first line to ToolWindow2
This should be it. I hope I haven't forgot anything. You can then open the two windows under Views->Other Windows
I'm trying to use an icon that I've added as a resource as the image on a button. I know it's possible because I can do it in other projects through the designer. However, I'm trying to do this with code. I added the icon as a resource to my project by following the steps in the accepted answer to this question. The resource is named CancelButtonIcon.
Now, I'm trying to add that icon as the image on a standard button with this code:
this.CancelButton.Image = (System.Drawing.Image)Properties.Resources.CancelButtonIcon;
However, I get an error message:
Cannot convert type 'System.Drawing.Icon' to 'System.Drawing.Image'
In the code that Visual Studio automatically generates when I use the designer, it looks like this:
((System.Drawing.Image)(resources.GetObject("SaveButton.Image")));
which results from manually adding a resource through the Properties window. How can I convert this icon resource to an image so it can be used on the button? Adding it through the designer is not an option (this button is created programmatically and thus isn't present in the designer).
You can use the Icon.ToBitmap method for this purpose. Note that a Bitmap is an Image.
CancelButton.Image = Properties.Resources.CancelButtonIcon.ToBitmap();
Not sure why, but any time I tried using the accepted answer's approach, the .ToBitmap() call was giving me array index out of bounds exceptions. I solved this by doing it this way instead:
System.Drawing.Icon.FromHandle(Properties.Resources.CancelButtonIcon.Handle).ToBitmap();