Custom action icon on android devices - android-layout

I am developing custom menu item by calling action layout, but when i am taping that action menu that pressing color is not applying total height giving some top and bottom margin.
Below is my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:minWidth="56dp"
android:id="#+id/voicemailNotificationCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:clickable="true"
android:background="#drawable/ab_pressedicon_bgcolor"
android:contentDescription="#string/voicemailnotification"
android:src="#drawable/ab_voicemail">
</ImageView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/vmNotificationTextCounter"
android:text="1"
android:visibility="visible"
android:layout_alignRight="#+id/voicemailNotificationCounter"
android:layout_marginRight="10dp"
android:gravity="center"
android:textColor="#fff"
android:includeFontPadding="false"
android:background="#drawable/notification_alertbg"
android:textSize="12sp"/>
</RelativeLayout>

Part of the problem is that you're not using an ImageButton.
Combining an image with text is possible with an ImageButton. You can even independently adjust the text and the image inside that ImageButton.
Hopefully, an ImageButton will work inside an action menu, I haven't actually tested that part yet.

Related

How to make multiple Textview selectable in a activity?

I am developing an Android app. It is just like an article reading app in which there are many textview (more than 10) under one activity.
Like -
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="#dimen/activity_vertical_margin" android:paddingLeft="#dimen/activity_horizontal_margin" android:paddingRight="#dimen/activity_horizontal_margin" android:paddingTop="#dimen/activity_vertical_margin" tools:context=".EnviarMensaje">
<TextView android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="My text is here" android:textSize="20sp" />
<TextView android:id="#+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="My text is here" android:textSize="20sp" />
<TextView android:id="#+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="My text is here" android:textSize="20sp" />
</RelativeLayout>
I want to make all these textview selectable when user touch for a long time on text, an option should come "select all". And when choosing the select all option, the Text of all Textview (From textView 1 to textView3) should select.
I tried - android:textIsSelectable=true
But after apply this, when I choose select all option, the Text is selected of only textView1 or textView2. Not selected all text on screen together.
Please help me.
Checkout this: https://stackoverflow.com/a/6179365
You can register the textviews in onCreate, then override onCreateContextMenu and getTextfrom each textview.

Android Material Design Toolbar and FAB Button crossing over

In the Google's Material Design specs they often shown the Floating Action Button lying over half the toolbar and have over the content.
http://www.google.com/design/spec/components/buttons-floating-action-button.html
But I have tried a few variations and there is still a gap between the toolbar and content, caused by the button.
<LinearLayout>
<include layout="#layout/toolbar" />
<include layout="#layout/fab_button" />
<ScrollView>
Content
</ScrollView>
</LinearLayout>
I have also tried placing both toolbar and FAB button in a FrameLayout and it also had the gap.
The FAB button code was taken from Google's samples, and I haven't had issues with having it overlap at the bottom of over a RecyclerView.
Is there a way to achieve this look shown in the Material Design Specs.
Add layout_anchor property in FAB and set it to Top View.
Make CoordinatorLayout as your root view, this would be best layout practice.
You can set FAB gravity using layout_anchorGravity attribute in FAB.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/viewA"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:background="#android:color/holo_blue_bright"
android:orientation="horizontal"/>
<LinearLayout
android:id="#+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:background="#android:color/holo_green_light"
android:orientation="horizontal"/>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="#drawable/ic_done"
app:layout_anchor="#id/viewA"
app:layout_anchorGravity="bottom|right|end"/>
</android.support.design.widget.CoordinatorLayout>
Check this out.
Hope this could help you.
Using Relative layout is the easiest to position a FAB in between 2 views. You can use elevation parameter for the fab to get it over the toolbar. Set the elevation of the FAB more that that of the toolbar.
<RelativeLayout 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"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
android:background="?attr/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<ListView
android:id="#+id/listview"
android:layout_below="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/favorite"
android:layout_alignBottom="#+id/toolbar"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
android:elevation="8dp"
android:layout_marginBottom="-32dp"
fab:fab_icon="#drawable/ic_favorite_outline_white_24dp"
fab:fab_colorNormal="#color/accent"
fab:fab_size="mini"
/>
</RelativeLayout>

Android centering an textview next to a imageview

I have an imageview and i want to put in the right a textview, but that will stay centered verticaly, so I can make my custom listview.
This photo can explain better:
My code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/icon1" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/imageView1"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Set your TextView's attribute
android:layout_centerVertical="true"
It would be even better if you set your image as a compound drawable inside the TextView (to the left of it):
android:drawableLeft="#drawable/icon1"
android:drawablePadding="8dp"
The two lines above are in the TextView definition and completely replace your ImageView.
This is a best practice and increases the overall performance, by flattening your layout hierarchy.
And remove the android:gravity="top" attribute in the parent.
Also, to make this the item row of a ListView, this android:layout_height="match_parent" should be android:layout_height="wrap_content"

can't get android custom dialog box to size properly

I'm trying to create a custom dialog box but it's both making it as wide as the screen (minus padding) but more importantly it's adding about an inch to the top in white (the background colour is red) above the first textview. What I want is a dialog box just as big as it needs to fill the content.
If I change any layout from fill_parent to wrap_content I get the contents about the size of the image and everything else (i.e. the text) is truncated.
What am I doing wrong?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/customdialog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/titledialog"
android:orientation="vertical" >
<TextView
android:id="#+id/textTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/titleback"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/title" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="24dp"
android:paddingTop="48dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="TextView" />
</LinearLayout>
<Button
android:id="#+id/buttonCustomDialogOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Close" />
I found the answer here
Android: How to create a Dialog without a title?
Apparently the top blank bit is the title of the layout and you cannot get rid of it unless you use an AlertDialog and not a Dialog.
ah, thanks for the update.
Android Dialog: Removing title bar
you can do it like this
Dialog dialog = new Dialog(context, R.style.FullHeightDialog);
(OR Try This)
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

Android Device ScreenSize Problem

in my Home Screen i have set one image as background, And set Three Image Button on That Background Image at Bottom of layout. it(Three Image Button) seems perfect in 480x854 screen Device but not in 240x320 Screen size of device. My XML Layout That I use is:
<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/inscreen">
<ImageView android:id="#+id/clip"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="95dip"
android:layout_gravity="bottom|center"
android:src="#drawable/selector"/>
<ImageView android:id="#+id/catagoryvid"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="55dip"
android:layout_gravity="bottom|center"
android:src="#drawable/selector1"/>
<ImageView android:id="#+id/search"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dip"
android:layout_gravity="bottom|center"
android:src="#drawable/selector2"/>
</FrameLayout>
Any help?
Thanks.
You should use relative layout for handling such type of problem, In which you can put the controls relatively regardless of screen size.

Resources