Any one could suggest how to reduce space between spinner items height having radio buttons.
My Code is below .
Layout
<Spinner android:layout_width="250dp"
android:layout_height="40dp"
android:id="#+id/spinnerCompany"
android:theme="#style/SpinnerTheme"
android:background="#android:drawable/btn_dropdown" />
Spinner Theme
<style name="SpinnerTheme">
<item name="android:layout_width" >fill_parent</item>
<item name="android:textSize" >15dp</item>
<item name="android:layout_width" >fill_parent</item>
<!--<item name="colorAccent">#00f</item>
<item name="colorControlNormal">#00f</item>-->
</style>
Activity Code
ArrayAdapter CompanyAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerItem, cls_static.ToArrayList(ListofCompnyFromDB));
CompanyAdapter.SetDropDownViewResource(Android.Resource.Layout.SelectDialogSingleChoice);
spinnerCompanyObj.Adapter = (CompanyAdapter);
Getting output like below any help would be appreciated.
You can add the android:dropDownWidth="100dp" in Spinner
<Spinner android:layout_width="250dp"
android:dropDownWidth="100dp"
android:layout_height="40dp"
android:id="#+id/spinnerCompany"
android:theme="#style/SpinnerTheme"
android:background="#android:drawable/btn_dropdown" />
There is running screenshot.
I have made a minor change like below and it get resolved.
Activity
CompanyAdapter.SetDropDownViewResource(Resource.Drawable.styl_spinner_style);
styl_spinner_style
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="37dp"
android:ellipsize="marquee"
android:checkMark="?android:attr/listChoiceIndicatorSingle"
android:textColor="#252c3b"/>
Related
I have made the splash screen from the manual:
I have created SplashActivity that extends from AppCompatActivity etc. Its works as expected.
But now I want set some animation to the splash activity and I am confused, because all that I put on the SplashActivity is unvisible (and now I cann't be to sure that the itself SplashActivity is visible).
Now I have deleted all excess stuff from the SplashActivity and start it as is:
// `MainLauncher` argument for my MainActivity is false now
[Activity(Theme = "#style/SplashTheme", NoHistory = true, MainLauncher = true)]
public class SplashActivity : Activity // AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState) // , PersistableBundle persistentState
{
base.OnCreate(savedInstanceState); // persistentState
this.SetContentView(Resource.Layout.LPreloader);
}
protected override void OnResume()
{
base.OnResume();
}
}
LPreloader.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical" >
<Button
android:id="#+id/my_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some element on Activity" />
</LinearLayout>
Theme in styles for the activity is:
<style name="SplashTheme" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBar">true</item>
</style>
I want to see for example the my_button on activity, but I have nothing. More than that: I set breakpoint on the line base.OnCreate(savedInstanceState); and its never stopped on it. I see just logo from #drawable/splash_screen and nothing.
If I create new Xamarin.Android project with same code - it works fine (I see the button). I cann't understand it. What is hinder to working in Xamarin.Forms project?
Remove Window background from splash theme and try it will work, as you except
<style name="SplashTheme" parent ="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowActionBar">true</item>
</style>
I have been having problems with incorporating a Progress Bar into my splash screen. I have an XML file called splash_setup,
<?xml version="1.0" encoding="utf-8"?>
<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="#color/background">
<bitmap
android:src="#drawable/splash"
android:tileMode="disabled"
android:gravity="top|center_horizontal" />
<ProgressBar
style="#android:style/Widget.ProgressBar.Small"
android:gravity="top|center_horizontal" />
</LinearLayout>
This file is used as background for 'splashTheme' (in Styles.XML) as following,
?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="splashTheme" parent="android:Theme">
<item name="android:windowBackground">#drawable/splash_setup</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
The splashTheme is used in splashActivity (the splash executes database initialisation and then finished),
[Activity(Label = "#string/appName", Theme = "#style/splashTheme",
MainLauncher = true, NoHistory = true)]
So to my problem... the splash_setup code runs fine without tags, but when they are in I get the following error,
android.content.res.Resources$NotFoundException: File res/drawable/splash_setup.xml from drawable resource ID #0x7f020002
Could anyone point out what I am doing wrong? Thanks!
What you have is a layout not a drawable. android:windowBackground attribute in style allows only drawable which may include shapes and/or layer lists. If you really wish to show a progressbar, then you need an activity.
I'm attempting to make a circular imageView with two borders.
The circular image is made with a library that only allows to make one border, with the app:civ_border_color property.
The second border is achieved by setting a background property.
My problem is, the second border, made with the background, is being cropped on the sides, like this:
The circular image
<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:background="#drawable/border"
android:padding="0dp"
android:layout_margin="0dp"
android:layout_height="200dp"
android:src="#drawable/mrwhite"
app:civ_border_width="3dp"
app:civ_border_color="#BF0404" />
The second border
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="1.9"
android:useLevel="false" >
<solid android:color="#android:color/transparent" />
<stroke
android:width="5dp"
android:color="#F2F2F2" />
</shape>
Change thicknessRatio value to 2
android:thicknessRatio="2"
A simple way to create RoundedImageView using ImageView and CardView
Check this example: https://github.com/SergeySharipov/RoundedImageView
Add the following dependency to your app module's build.gradle file:
dependencies {
implementation 'com.android.support:cardview-v7:27.1.0'
}
Add the code to your layout and change "YOUR_PICTURE":
<android.support.v7.widget.CardView
android:id="#+id/card_view_for_image"
android:foreground="#drawable/shape"
android:layout_margin="2dp"
android:layout_width="200dp"
android:layout_height="200dp"
app:cardCornerRadius="100dp">
<ImageView
android:id="#+id/rounded_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/YOUR_PICTURE" />
</android.support.v7.widget.CardView>
Create shape.xml in drawable and add this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke
android:width="10dp"
android:color="#f44336" />
</shape>
</item>
<item>
<shape android:shape="oval">
<stroke
android:width="5dp"
android:color="#ffffff" />
</shape>
</item>
</layer-list>
Hi I use C# and Xamarin to develop my new application and ran into many problems using this platform. Is it possible to customize menu items inside NavigationView using xamarin? all I found are the valid properties for the menu items.
But what if instead of this:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/itemOne"
android:title="Go to page one" />
<item
android:id="#+id/itemTwo"
android:title="Go to page two" />
</menu>
I want to do this:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<TextView></TextView>
<Button></Button>
<SomeOtherControlHere></SomeOtherControlHere>
</menu>
Is it possible using xamarin? What are my other options?
Aside from that I found that Xamarin API's are very restrictive, for example you cant use custom ttf fonts directly inside xml to set the fonts for menu items:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/itemOne"
android:title="Go to page one"
android:fontFamily="MyCustomFontName Or MyPathToFonts" /> <-- NOT VALID
</menu>
Also if I apply style for an entire menu items container it is also not possible to use custom fonts, the only fonts we can use is the built in fonts...
Even if I get reference inside my Activity to an individual menu item (IMenuItem), there is no property or function to set font family.
It's possible to define a more complex NavigationView. Just put the child controls inside the NavigationView-Tag. For example, this is how I use the NavigationView to implement a footer. There are no restrictions to the child controls so you can you Buttons etc. as well:
<android.support.design.widget.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
local:headerLayout="#layout/drawer_header"
local:theme="#style/NavigationDrawerStyle"
local:menu="#menu/drawer_menu">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:orientation="vertical">
<TextView
android:id="#+id/empty_spacer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:clickable="false"
android:text="" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="#drawable/footer_small"
android:orientation="vertical"
android:weightSum="1" />
</LinearLayout>
</android.support.design.widget.NavigationView>
To change the TextSize of the items for example, you have to define an own style:
<style name="NavigationDrawerStyle">
<item name="android:textSize">24sp</item>
<!-- more properties -->
</style>
Then assign it to your NavigationView:
<android.support.design.widget.NavigationView app:theme="#style/NavigationDrawerStyle">
<!-- ... -->
</android.support.design.widget.NavigationView>
This is how I format the Navigation Menu Item which starts by icon, then menu text and the last one is number. It look like the one in gmail app.
OnCreate
navigationView = FindViewById<NavigationView>(Resource.Id.wnl_nav_view);
//Add customize menu item style
IMenu menuNav = navigationView.Menu;
View view = View.Inflate(this, Resource.Layout._drawerMenuItemTemplate, null);
IMenuItem logoutItem = menuNav.FindItem(Resource.Id.nav_mail);
MenuItemCompat.SetActionView(logoutItem, view);
TextView txtNewNumber = view.FindViewById<TextView>(Resource.Id.txtNewNumber);
_drawerMenuItemTemplate.axml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/primary_text"
android:text="3/30"
android:id="#+id/txtNewNumber"
android:layout_gravity="right"
android:fontFamily="#string/abc_font_family_display_2_material"
android:textSize="13sp"
android:textStyle="bold"
android:paddingRight="6dp"
android:layout_marginTop="14dp" />
</FrameLayout>
I'm creating Android app using Xamarin for Android. I want to use in my app NavigationDrawer, so I downloaded and installed 'Android Design Library' from Xamarin Components Store. Then I edited my layout for this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawerLayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/articlesListView" />
<android.support.design.widget.NavigationView
android:id="#+id/navView"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/navHeader"
app:menu="#menu/navMenu"/>
</android.support.v4.widget.DrawerLayout>
navHeader.axml:
<?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="192dp"
android:background="?attr/colorPrimaryDark"
android:padding="16dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:orientation="vertical"
android:gravity="bottom">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"/>
</LinearLayout>
and menu/navMenu.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/nav_home"
android:title="Home" />
<item
android:id="#+id/nav_messages"
android:title="Messages" />
<item
android:id="#+id/nav_friends"
android:title="Friends" />
<item
android:id="#+id/nav_discussion"
android:title="Discussion" />
</group>
<item android:title="Sub items">
<menu>
<item
android:title="Sub item 1" />
<item
android:title="Sub item 2" />
</menu>
</item>
</menu>
Unfortunately while compiling, I received following error:
C:\Project\Project\File.axml: Error APT0000: No resource found that
matches the given name (at 'headerLayout' with value
'#layout/navHeader'). (APT0000) (AppName)
C:\Projects\Project\File.axml(0,0): Error APT0000: No resource found
that matches the given name (at 'menu' with value '#menu/navMenu').
(APT0000) (AppName)
Somebody knows how I may solved this problem?
Thank you in advance
I had the same issue.
I simply put lower case letters in the name of the header layout file and it worked.
Before (Failing with same error message):
app:headerLayout="#layout/DrawerHeader"
After:
app:headerLayout="#layout/drawerheader"
Named Your layout file and menu with the small letter.
app:headerLayout="#layout/drawerheader"
app:menu="#menu/drawermenu"
Had the same problem. Guess it is a bug. C# code addition (in OnCreate() method of your activity) of navigation header view and menu view works fine for me. That is done with NavigationView methods InflateMenu and inflateHeaderView.
EDIT
First delete
app:headerLayout="#layout/navHeader"
and
app:menu="#menu/navMenu"
from your Navigation Drawer layout and insert
navigationView = FindViewById<NavigationView>(Resource.Id.navView);
navigationView.InflateHeaderView(Resource.Layout.navHeader);
navigationView.InflateMenu(Resource.Menu.navMenu);
somewhere in onCreate() method of your activity in question.