How to run a simple link with the following command?
<TextView
android:text="text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView1" />
TextView textView = FindViewById<TextView>(Resource.Id.textView1);
textView.TextFormatted = Android.Text.Html.FromHtml("https://www.google.com");
textView.MovementMethod = Android.Text.Method.LinkMovementMethod.Instance;
These work:
textView.TextFormatted = Android.Text.Html.FromHtml("google");
textView.TextFormatted = Android.Text.Html.FromHtml("https://www.google.com");
This also does not work:
<TextView
android:text="text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:id="#+id/textView1" />
textView.TextFormatted = Android.Text.Html.FromHtml("<u>" + "https://www.google.com" + "</u>");
LinkMovementMethod only works for the links in the text .
In Html <a> represents a hyperlink to a url , but <u> is not hyperlink ,it is just an underline .
Avoid using the element where it could be confused for a hyperlink .
Related
I looked everywhere, but for the moment works.
here is my code:
<Spinner
android:id="#+id/departement"
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="#color/colorAccent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_vertical|center_horizontal"
/>
Spinner departement = (Spinner)sender;
((TextView)departement.GetChildAt(0)).SetForegroundGravity(GravityFlags.CenterHorizontal);
((TextView)departement.GetChildAt(0)).SetTextColor(Color.White);
the color works, but the center position does not. do you have an idea ?
You can use a new xml to define the content of that item in Spinner.
And cusotmize the style in that xml .
Item.xml
<?xml version="1.0" encoding="utf-8" ?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" //center
android:textColor="#android:color/holo_red_dark"/> //Textcolor
Set in Adapter
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this,Resource.Layout.Item,items);
departement.Adapter = adapter;
I'd like to center the following LinearLayout to the center of his parent programatically:
<LinearLayout
android:id="#+id/SignButtonsLinearLayout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<homes.shared.components.customviews.HomesButton
android:id="#+id/CheckListPDFClosureButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dip"
android:drawableLeft="#drawable/CheckListPDFClosure"
android:background="#drawable/MainBlueButton"
style="#style/WhiteDeliveryNoteMenuBold"
android:text="#string/CheckListPDFClosure" />
<homes.shared.components.customviews.HomesButton
android:id="#+id/SignatureAndCloseButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/SignatureAndClosure"
android:background="#drawable/MainBlueButton"
style="#style/WhiteDeliveryNoteMenuBold"
android:text="#string/SignatureAndClose" />
</LinearLayout>
I have instanced the LinearLayout in code like this:
LinearLayout ll = this.FindViewById<LinearLayout>(Resource.Id.SignButtonsLinearLayout);
but the object doesn't have LayoutGravity property
You can do it quick hand like this:
LinearLayout ll = this.FindViewById<LinearLayout>(Resource.Id.SignButtonsLinearLayout);
ll.SetGravity(GravityFlags.Center);
Or you can do it this way too:
LinearLayout ll = this.FindViewById<LinearLayout>(Resource.Id.SignButtonsLinearLayout);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)lin.LayoutParameters;
layoutParams.Gravity = GravityFlags.Center;
ll.LayoutParameters = layoutParams;
Some more info can be found in this SO reply here as well.
EDIT:
Apologies, to adjust the layout gravity which sets the gravity of the View or Layout relative to its parent then you should just be able to add this attribute to your axml layout file. android:layout_gravity="center" like this:
<LinearLayout
android:id="#+id/SignButtonsLinearLayout"
android:layout_gravity="center"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
The other option is to stack layouts, so you could wrap your linear layout in a relative layout like this and use center in parent.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:focusableInTouchMode="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/SignButtonsLinearLayout"
android:layout_centerInParent="true"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</LinearLayout>
</RelativeLayout>
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>`
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.
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