I have to give my MaterialSpinner the following border:
I have the following MaterialSpinner
<fr.ganfra.materialspinner.MaterialSpinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner"
app:ms_arrowColor="#000000"
app:ms_arrowSize="16dp"
app:ms_floatingLabelColor="#A9A9A9"
app:ms_floatingLabelText="Избор на група"
app:ms_hint="Избор на група"
app:ms_hintColor="#000000"
android:padding="10dp"
android:layout_gravity="center"
android:background="#drawable/material_spinner_border"/>
material_spinner_border.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- View background color -->
<solid
android:color="#000000" >
</solid>
<!-- View border color and width -->
<stroke
android:width="1dp"
android:color="#000000" >
</stroke>
<!-- The radius makes the corners rounded -->
<corners
android:radius="2dp" >
</corners>
</shape>
When I run the app the border doesn't appear on screen
How to put a border around MaterialSpinner Xamarin.Android?
Set your MaterialSpinner ms_arrowColor color as white to hide the arrow:
<fr.ganfra.materialspinner.MaterialSpinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinner"
app:ms_floatingLabelColor="#A9A9A9"
app:ms_floatingLabelText="Избор на група"
app:ms_hint="Избор на група"
app:ms_hintColor="#000000"
app:ms_arrowColor="#ffffff"
app:ms_arrowSize="16dp"
android:background="#drawable/material_spinner_border"
android:layout_margin="5dp"
/>
Add your arrow image to your project, for example:
Then, modify your material_spinner_border like this:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape>
<stroke android:width="3dp" android:color="#000000" />
<corners android:radius="4dp" />
<padding android:bottom="0dp" android:left="3dp" android:right="3dp" android:top="0dp" />
</shape>
</item>
<item >
<bitmap android:gravity="center|right" android:src="#drawable/myarrow" />
</item>
</layer-list>
</item>
</selector>
Effect.
Update:
Set spinner background after set the Spinner adapter will solve this issue:
string[] ITEMS = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6" };
var adapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleSpinnerItem, ITEMS);
adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
var spinner = FindViewById<MaterialSpinner>(Resource.Id.spinner);
spinner.Adapter = adapter;
spinner.Background = Drawable.CreateFromXml(Resources, Resources.GetXml(Resource.Drawable.material_spinner_border));
Here is a picture what it looks like:
I forgot to tell you that my backgroung is dark if it matters
Related
I want to add a space and shade between each element in listview.
How the tool is drawn xml?
Create a xml file Shadow.xml in Android drawable folder.
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape
android:shape="rectangle">
<solid android:color="#android:color/darker_gray" />
<corners android:radius="5dp"/>
</shape>
</item>
<item android:right="6dp" android:left="6dp" android:bottom="9dp">
<shape
android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
Uasge: Set the shadow with background of Layout. Use divider property to set the space between each element in listview.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center"
android:background="#drawable/shadow"
android:orientation="vertical">
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="20px"
android:divider="#android:color/darker_gray"
android:layerType="software"
/>
</LinearLayout>
MainActivity:
ListView listView = FindViewById<ListView>(Resource.Id.listview);
string[] s = new string[] { "a", "b", "c","d","e","f","g","h","i","j","k" };
ArrayAdapter<string> arrayAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, s);
listView.Adapter = arrayAdapter;
I would like to implement a toolbar in my app, but I don't necessarily want to support versions of android that are older than Oreo.
I have a toolbar, it shows up, it replaced the action bar, but I don't know how to make it act like an action bar and place buttons on it properly.
This is the xml of the activity I'd want the toolbar for:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<Toolbar
android:minHeight="?android:attr/actionBarSize"
android:title="Lyrics"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:titleTextColor="#DDDDDD"
android:background="#112244"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:id="#+id/lyricsToolbar">
</Toolbar>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:minHeight="30px"
android:id="#+id/lyricsListView"/>
</LinearLayout>
And this is in the .cs file:
var lyricsToolbar = FindViewById<Toolbar>(Resource.Id.lyricsToolbar);
SetActionBar(lyricsToolbar);
The toolbar does appear, but I don't know how to properly put buttons on it. All the tutorials and code I've found are putting a menu on an appcompat support library version. I'd like to add an "add lyrics" button to the toolbar on it's right side and nothing else (it would be just a plus sign and if you click it it opens up another activity where adding new lyrics is possible).
Is this a wrong approach?
How should I do this? Should I make the app more backward-compatible, otherwise I can't properly use toolbars?
Any help is appreciated,
Thank you
Do you want to achieve it like following GIF?
If so, you could add this plus icon directly like following layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
>
<Toolbar
android:minHeight="?android:attr/actionBarSize"
android:title="Lyrics"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:titleTextColor="#DDDDDD"
android:background="#112244"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:id="#+id/lyricsToolbar">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_menu_add"
android:layout_gravity="end"
android:id="#+id/Toolbar_add"
/>
</Toolbar>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:minHeight="30px"
android:id="#+id/lyricsListView"/>
</LinearLayout >
And set the click event listener.
[Activity(Label = "#string/app_name", Theme = "#style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
var imageView =FindViewById<ImageView>(Resource.Id.Toolbar_add);
imageView.Click += ImageView_Click;
}
private void ImageView_Click(object sender, System.EventArgs e)
{
var intent=new Intent(this, typeof(LyricsActivity));
StartActivity(intent);
}
If you want to hide the action bar, please do not forget to add the <item name="windowNoTitle">true</item> in styles.xml like following code.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowNoTitle">true</item>
</style>
I make a menu according to this guide: https://www.youtube.com/watch?v=aGO-xcpJUBs
How to change the text color and background of the menu item?
my files:
styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MyStyle"
parent="#android:style/Theme.DeviceDefault">
</style>
</resources>
2.menu.xml
<?xml version="1.0" encoding="utf-8" ?>
<menu tools.context=".MainActivity"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="#string/name"
android:showAsAction="always"
android:id="#+id/iname"/>
<item android:title="#string/email"
android:showAsAction="always"
android:id="#+id/iemail"/>
</menu>
adding this line does not give anything:
android:textColor="#android:color/black"
Change the background of the menu item
You could add an attribute in your styles.xml to change the menu background color :
<item name="android:itemBackground">#FFFCF8FA</item>
Here is my styles.xml :
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="Theme.MyTheme" parent="Theme.MyTheme.Base">
</style>
<!-- Base theme applied no matter what API -->
<style name="Theme.MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionModeOverlay">true</item>
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:itemBackground">#FF8898F1</item>
</style>
</resources>
Change the text color of the menu item
You can implement this feature programmatically, change the color of the MenuItem text easily by using SpannableString instead of string.
Here is my code :
public override bool OnCreateOptionsMenu(IMenu menu)
{
MenuInflater.Inflate(Resource.Menu.menu_form, menu);
for (int i = 0; i < menu.Size(); i++)
{
IMenuItem item = menu.GetItem(i);
Android.Text.SpannableString spanString = new Android.Text.SpannableString(menu.GetItem(i).ToString());
spanString.SetSpan(new ForegroundColorSpan(Android.Graphics.Color.Red), 0, spanString.Length(), 0); //fix the color to red
item.SetTitle(spanString);
}
return true;
}
Effect.
How to add text color to ListView ?
The background is white for Layout and I need the text color to be darkgray or black.
--UI
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ListView1" />
</LinearLayout>
-- code :
listV= FindViewById<ListView>(Resource.Id.ListView1);
itemlist = new List<string>();
itemlist.Add("item1");
itemlist.Add("item2");
itemlist.Add("item3");
itemlist.Add("item4");
itemlist.Add("item5");
itemlist.Add("item6");
itemlist.Add("item7");
itemlist.Add("item8");
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, itemlist);
listV.Adapter = adapter;
Thanks
Create a layout file containing the textview you want with textSize, textStyle, color etc preferred by you and then use it with the ArrayAdapter.
e.g. mytextview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tview"
android:textColor="#color/yourColor"
android:padding="5sp"
android:layout_width="fill_parent"
android:background="#drawable/rectgrad"
android:singleLine="true"
android:gravity="center"
android:layout_height="fill_parent"/>
and then use it with your ArrayAdapter as usual like
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, R.layout.mytextview, itemlist);
i have problem with my code. i have created button "sign up", i want when i click on that button a dialog called "dialog_signup appear.
The problem is it doesnt appear. and i always get this error so far
**2>A numeric comparison was attempted on "$(_DeviceSdkVersion)" that evaluates to "" instead of a number, in condition "$(_DeviceSdkVersion) >= 21".
2>Build FAILED.
2>
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========**
Here is my code
MainActivity.cs
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Content.Res;
namespace GameLandPlus
{
[Activity(Label = "GameLandPlus", MainLauncher = true, Icon = "#drawable/icon")]
public class MainActivity : Activity
{
private Button mbtnSignup;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
mbtnSignup = FindViewById<Button>(Resource.Id.btnsignup);
mbtnSignup.Click += (object sender, EventArgs args) =>
{
FragmentTransaction transaction = FragmentManager.BeginTransaction();
dialog_signup signupDialog = new dialog_signup();
signupDialog.Show(transaction, "dialog fragment");
};
}
}
}
-->
main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/background_light"
android:weightSum="100"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:src="#drawable/images"
android:layout_width="match_parent"
android:layout_weight="20"
android:layout_height="0dp"
android:id="#+id/imageView1" />
<TextView
android:text="Create Account"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_weight="20"
android:layout_height="0dp"
android:textColor="#000000"
android:id="#+id/createaccount"
android:textSize="35sp"
android:gravity="center"
android:textStyle="bold" />
<Button
android:layout_width="match_parent"
android:layout_weight="10"
android:layout_height="0dp"
android:gravity="center"
android:id="#+id/signin"
android:textColor="#FFFFFF"
android:background="#drawable/butto1"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:text="Sign in"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5" />
<TextView
android:text="or"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_weight="15"
android:layout_height="0dp"
android:id="#+id/or"
android:textColor="#000000"
android:textSize="35sp"
android:gravity="center"
android:textStyle="bold" />
<Button
android:text="Sign Up"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:id="#+id/btnsignup"
android:textColor="#FFFFFF"
android:background="#drawable/butto1"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:shadowColor="#00ffffff"
android:shadowRadius="5"
android:drawableRight="#drawable/goodmess" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="35"
android:minHeight="15px"
android:minWidth="15px">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar1"
android:background="#drawable/progressbar"
android:indeterminate="true"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
-->
the dialog page i want to pop up when i click on the button
dialogSignup.axml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#F1F3F4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minHeight="300dp"
android:minWidth="300dp">
<EditText
android:inputType="textPersonName"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/Firstname"
android:background="#drawable/editstyle"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="25dp"
android:hint="Username"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000" />
<EditText
android:layout_below="#+id/Firstname"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/textEmail"
android:background="#drawable/editstyle"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:hint="Email/Phone Number"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000" />
<EditText
android:layout_below="#+id/textEmail"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/password"
android:background="#drawable/editstyle"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:hint="Password"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000" />
<Button
android:layout_below="#+id/password"
android:text="Sign Up"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/btnDialogEmail"
android:textColor="#FFFFFF"
android:background="#drawable/butto1"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:shadowColor="#00ffffff"
android:shadowRadius="5"
android:drawableRight="#drawable/goodmess" />
</RelativeLayout>
-->
and the dialog_signup.cs
using Android.Views;
using Android.Widget;
namespace GameLandPlus
{
class dialog_signup:DialogFragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState)
{
base.OnCreateView(inflater, container, saveInstanceState);
var view = inflater.Inflate(Resource.Layout.dialogSignup, container, false);
return view;
}
public override void OnActivityCreated(Bundle savedInstanceState)
{
Dialog.Window.RequestFeature(WindowFeatures.NoTitle);//set title
base.OnActivityCreated(savedInstanceState);
Dialog.Window.Attributes.WindowAnimations = Resource.Style.dialog_animation;
}
}
}
-->
i do not include the slideup/slideright/butto1 because is the drawable file.
Please can u check on it.
I already change emulator so far. but i dont know where is the problem.
Any suggestion?