Add animation when USer slide the button - xamarin.android

I have use swipebutton by 2.0.0 and i want like this animation when user swipe the button and add white background on swipe button where he place the finger.
Here is my Code i dont know how to add the sliding white background
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
android:background="#F8F9FA"
android:gravity="center"
android:layout_gravity="center">
<View
android:background="#FF4C7485"
android:layout_marginTop="0dp"
android:layout_height="1dp"
android:layout_width="match_parent"/>
<com.ebanx.swipebtn.SwipeButton
android:id="#+id/swipeButton1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:layout_marginStart="20dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-8dp"
app:button_image_disabled="#drawable/check_circle_outline"
app:button_image_enabled="#drawable/check_circle_outline"
app:button_background="#drawable/swipe_button"
app:button_bottom_padding="18dp"
app:button_left_padding="20dp"
app:button_right_padding="20dp"
app:button_top_padding="12dp"
app:inner_text="Send"
app:inner_text_background="#drawable/round_button"
app:inner_text_color="#android:color/white"
app:inner_text_size="16sp"
app:inner_text_top_padding="10dp"
app:inner_text_left_padding="1dp"
app:inner_text_bottom_padding="15dp" />
</RelativeLayout>

Related

Imageview Inside Cardview Has A Image Src Which Bounds Out Of Imageview

I have a CardView with rounded corners, inside the CardView a ImageView is present.The issue is when i add the source inside the image the image goes out of ImageView hiding the round corners.
I have tried the code given below on macBook pro which produced the following results :
`<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:elevation="10dp"
app:cardCornerRadius="10dp"
android:layout_margin="5dp"
app:cardPreventCornerOverlap="false" >
<ImageView
android:id="#+id/card_view_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/competition_background"
android:scaleType="fitXY"
/>
</android.support.v7.widget.CardView>`
Try setting a defined width and height for your imageview. If your image is very large it will expand beyond the cardview. You could also choose to reduce the size of the image, which will result in a smaller apk. This is something to keep in mind when developping an android application. Never add larger resources than needed to your project.
So you could try something like this:
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:elevation="10dp"
app:cardCornerRadius="10dp"
android:layout_margin="5dp"
app:cardPreventCornerOverlap="false" >
<ImageView
android:id="#+id/card_view_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/competition_background"
android:scaleType="fitXY"
/>
</android.support.v7.widget.CardView>`
Another option is to add match_parent to your imageview but add a margin so it not expanded to the corners of your cardview:
<android.support.v7.widget.CardView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:elevation="10dp"
app:cardCornerRadius="10dp"
android:layout_margin="5dp"
app:cardPreventCornerOverlap="false" >
<ImageView
android:id="#+id/card_view_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="12dp"
android:src="#drawable/competition_background"
android:scaleType="fitXY"
/>
</android.support.v7.widget.CardView>`

how to combine status bar and toolbar with gradient in xamarin android

I want to combine status bar and toolbar with gradient like this
I have tried to set status bar transparent and make the toolbar big and set the gradient .
But It also makes your UI goes under the Soft navigation keys.
And also soft keyboard is covering the EditTexts.
android:windowSoftInputMode="adjustPan" not working
if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
{
Window window = Window;
window.AddFlags(WindowManagerFlags.LayoutNoLimits);
window.AddFlags(WindowManagerFlags.TranslucentNavigation);
}
Is there any way only the status bar make transparent rather than transparent both status bar and navigation button on the bottom.
You could alse do like this,add the code into the OnCreate method :
protected override void OnCreate(Bundle savedInstanceState)
{
if (Build.VERSION.SdkInt >= Build.VERSION_CODES.Kitkat)
{
Window w = Window;
w.AddFlags(WindowManagerFlags.TranslucentStatus);
w.SetSoftInputMode(SoftInput.StateHidden|SoftInput.AdjustResize);
}
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_other);
}
then create the gradient.xml in Resources/drawable :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:angle="135"
android:startColor="#f56f2c"
android:endColor="#fa9f46"/>
</shape>
at last in the layout.xml :
<?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:orientation = "vertical"
android:layout_height="match_parent"
android:fitsSystemWindows= "true"
android:background= "#drawable/gradient"
>
<!--use Toolbar-->
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="标题"
app:titleTextColor="#fff"
app:subtitle="副标题"
app:subtitleTextColor="#fff"/>
<!--if dont use Toolbar,RePresent Toolbar-->
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="44dp">
<ImageView
android:layout_gravity="center_vertical"
android:src="#drawable/ic_arrow_back_white_24dp"
android:layout_marginLeft="10dp"
android:layout_width="35dp"
android:layout_height="35dp" />
<TextView
android:layout_gravity="center_vertical"
android:textSize="25sp"
android:gravity="center_horizontal"
android:textColor="#fff"
android:text="Test Title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="#+id/scrollView1"
android:background = "#fff" //set the background color of your content
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation ="vertical" >
<!--your content -->
...
</LinearLayout>
</ScrollView>
</LinearLayout>
Why don't you set the color of status bar same as the startColor of gradient and let the toolbar start from where it does.
Create a static method that sets the status bar colour something like below:
public static void SetStatusBarGradiant(Activity activity)
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
Window window = activity.Window;
Drawable background = ResourcesCompat.GetDrawable(activity.Resources, Resource.Drawable.abc_ab_share_pack_mtrl_alpha, null);
window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
window.SetStatusBarColor(Android.Graphics.Color.Transparent);
window.SetNavigationBarColor(Android.Graphics.Color.Transparent);
window.SetBackgroundDrawable(background);
}
}
Then add a gradient.xml in drawable something like below see to it you set the start color and end color as per your requirement:
gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:angle="90"
android:startColor="#FFFF0000"
android:endColor="#FF00FF00"
android:type="linear" />
</shape>
</item>
</selector>
Goodluck
Revert if you have queries

launch spinner on click of a button

I'm working on Xamarin android. I want a spinner to show up on a button click or the spinner should be on top of a button, the other way I can say. Sounds crazy but that's the stuff I got in my head a couple of days back! Yeah I've seen Spinner. May be what I'm asking is not part of the plan, but I wanna implement that!
UPDATE 2: Let me explain with an example.
Consider the Web 2.0 scientific calculator. There is a button π. You long press the button and you will get a drop down. The constant that you select from the drop down will be displayed in the textbox. I want the same functionality with the spinner. Just the difference is I want it on the button click rather than a long press. Hope I'm clear now.
That's the part of code I tried with:
<!--main.axml-->
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:id="#+id/myTitle">
<!--some stuff-->
<ImageButton android:onClick="onClick"
android:id="#+id/btnPi"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:padding="100dip"
android:src="#drawable/pi" />
<Spinner
android:onClick="onClick"
android:id="#+id/btnConst"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:prompt="#string/cons" />
<!--And few other stuffs-->
</LinearLayout>
<!--Strings.xml-->
<string name="cons">const</string>
<string-array name="ConsArray">
<item>Angstrom star</item>
<item>Faraday constant</item>
<item>Planck constant</item>
<item>Rydberg constant</item>
<item>Stefan-Boltzmann constant</item>
<item>electric constant</item>
<item>mag. constant</item>
<item>neutron mass</item>
</string-array>
It doesn't matter's to me whether I use a Button or a ImageButton ! I'm happy with either of it. Basically I just want a drop-down menu to popup, as soon as I click that button. Can anyone help me with this? Thanks in advance.
UPDATE: When I worked on York Shen's answer , I got this blank space occupied by the spinner:
I want a spinner to show up on a button click.
You could put a Button on Spinner by using a FrameLayout :
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:id="#+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/planet_prompt"
/>
<Button
android:id="#+id/bt_spinner"
android:text="Spinner Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</FrameLayout>
Then, every time your Button is click, you could use spinner.PerformClick() method to show your Spinner :
bt_spinner.Click += (sender, e) =>
{
spinner.PerformClick();
};
Effect.
Update :
I cant reproduce your problem, but here is my complete code from the document, you could use it and try again :
spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.planets_array, Android.Resource.Layout.SimpleSpinnerItem);
adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
spinner.Adapter = adapter;
bt_spinner.Click += (sender, e) =>
{
spinner.PerformClick();
};
...
private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
Spinner spinner = (Spinner)sender;
string toast = string.Format("The planet is {0}", spinner.GetItemAtPosition(e.Position));
Toast.MakeText(this, toast, ToastLength.Long).Show();
}
In your XAML, set the spinner to not be visible. In your onClick event, set change the visibility. You may have to do more in onClick if you want the things below the spinner in the linear layout to move out of the way.

Keyboard Overlaps Edittext - Activity Fullscreen

I am working on chat application where Edittext and send button is at bottom.
Activity is fullscreen, hidden navigation and status bar.
I need to push edittext and send button up when keyboard comes into focus.
I tried to set android:windowSoftInputMode="adjustResize" but it didn't worked.
I tried using AndroidBug5497Workaround.assistActivity(this) class referred from https://github.com/madebycm/AndroidBug5497Workaround but it didn't worked.
Below is my activity theme and code in activity to hide bar and make full screen :
decorView = getWindow().getDecorView();
uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
Theme :
<style name="AppTheme_DarkStatus" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryveryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
XMl :
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/include_view"
android:isScrollContainer="true"
android:background="#android:color/white">
<com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="#+id/lv_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/rl_send"
android:divider="#null"
android:fadeScrollbars="false"
android:fadingEdge="none"
android:overScrollMode="never"
android:scrollbars="none"
ptr:ptrHeaderSubTextColor="#color/c_input_text_color"
ptr:ptrHeaderTextColor="#color/c_input_text_color"
ptr:ptrOverScroll="false"
ptr:ptrPullLabel="Pull to refresh"
ptr:ptrRefreshLabel="Loading..."
ptr:ptrReleaseLabel="Release to refresh"
ptr:ptrRotateDrawableWhilePulling="true"
ptr:ptrShowIndicator="false" >
</com.handmark.pulltorefresh.library.PullToRefreshListView>
<RelativeLayout
android:id="#+id/rl_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/c_white"
android:gravity="center" >
<View
android:id="#+id/view_dummy"
android:layout_width="match_parent"
android:layout_height="#dimen/d_diff_p5dp"
android:background="#color/c_text_light_color" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/view_dummy"
android:layout_toLeftOf="#+id/btn_send"
android:layout_marginRight="#dimen/d_diff_5dp"
android:layout_marginLeft="#dimen/d_diff_10dp"
android:layout_marginTop="#dimen/s_diff_7sp"
android:layout_marginBottom="#dimen/s_diff_7sp"
android:background="#drawable/opawhite_rectcorner_all" android:id="#+id/relativeLayout">
<EditText
android:id="#+id/et_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/d_diff_1dp"
android:background="#null"
android:focusableInTouchMode="true"
android:maxHeight="100dp"
android:hint="Type here..."
android:maxLength="150"
android:textSize="#dimen/s_diff_16sp"
android:padding="#dimen/s_diff_6sp"
android:textColorHint="#color/c_input_text_color"
android:textColor="#color/c_black" />
</RelativeLayout>
<Textview
android:id="#+id/btn_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/c_white"
android:text="Send"
android:padding="#dimen/d_diff_5dp"
android:layout_marginRight="#dimen/d_diff_5dp"
android:gravity="center"
android:textColor="#color/c_orange_main"
android:textSize="#dimen/s_diff_16sp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
</RelativeLayout>
I want to show edittext and send button above keyboard but it overlaps edittext.
Thanks!
The property android:windowSoftInputMode="adjustResize" doesn't work with full screen activity, you have to remove activity full screen flags in order to get advantage of adjust resize.
see this:
A fullscreen window will ignore a value of SOFT_INPUT_ADJUST_RESIZE for the window's softInputMode field; the window will stay fullscreen and will not resize.

TextView text is not centred

I am trying to centre some code in my text view but it seems to be persistently left aligned:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_above="#+id/myButtons">
<!-- Text -->
<TextView
android:id="#+id/myText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="22sp"
android:text="Test"
android:textStyle="bold" />
<!-- And the thumbnail -->
<ImageView
android:id="#+id/image"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:contentDescription="#string/image_text"
android:layout_gravity="center" />
</LinearLayout>
The image (when there is one, sometimes it is set to Visibility.GONE) is centre aligned okay. It's just I can't get the text to centre align.
Any thoughts welcome. Thanks!
add android:gravity="center_horizontal|center_vertical" in your textview attribute to make the center
<TextView
android:id="#+id/myText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:textSize="22sp"
android:text="Test"
android:textStyle="bold" />
to make the Textview fillParent after imageview is gone
set height of the textview fill_parent Programatically like
textview.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT,0));
^ ^
height width

Resources