How to give title and subtitle to a material design button? - android

I want to make a material button having a title and subtitle
eg:- title with big text and subtitle with small text.

The Simple way is-
You can Use a Layout as a button. In the layout you can Use a Title and Subtitle and You set the SetOnClickListner on the Layout.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="methodClick"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subtitle"/>
</LinearLayout>

Related

In Android can we use style and background in Textview or Edittext

when I am trying to add background and style but style effects are not shown in text view...
<TextView
android:id="#+id/tvModelYearMax"
style="#style/Widget.AppCompat.Spinner.DropDown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/transparent_square"
android:elevation="#dimen/normal_elevation"
android:text="2018" ></TextView>
Use this approach. Set background style in relative layout.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/transparent_square">
<Spinner
android:id="#+id/tvModelYearMax"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>

Use default title text view style for customize title text for AlertDialogs

I was needed to create a custom title view to be able show message and title, when the list appears. Because the list appears in the dialog's content area. So the dialog cannot show both a message and a list.
My custom view is a LinearLayout :
<?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="match_parent"
android:orientation="vertical"
android:padding="24dp"
android:paddingBottom="20dp"
style="#style/Base.Theme.AppCompat.Dialog.Alert"
>
<TextView
android:id="#+id/alert_dialog_custom_title_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:textSize="20sp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/alert_dialog_custom_message_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"/>
</LinearLayout>
Padding values and text size was given in accordance with the information given material design guidelines
However, This appearance is different from the default one.
my question:
How can I create a textView that has a same style with default one ?
Maybe there is a way like setting a style to my TextView
Edit : I just want to set style attribute that makes its visuality same as default AlertDialog.
My textview is already like this:
<TextView
android:id="#+id/alert_dialog_custom_title_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="messsage"
android:layout_marginBottom="20dp"
android:textSize="20sp"
android:textStyle="bold"
/>
I want to do that just like this :
<TextView
android:id="#+id/alert_dialog_custom_title_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="messsage"
style="?android:attr/titleTextStyle"
/>
In your style you can use this
<style name="TextAppearance.AlertDialogPro" parent="android:TextAppearance" />
for you textview you can add style
<TextView
android:id="#+id/alert_dialog_custom_title_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="messsage"
style="#style/TextAppearance.AlertDialogPro"
android:layout_marginBottom="20dp"
android:textSize="20sp"
android:textStyle="bold"
/>

how to display textview below button in relativeLayout

in the below xml layout, i have two buttons at the same position and they will do their function based on the visibilty set. now i tried to place two textviews
below the buttons, i want the text views to be below both buttons so I used
android:layout_below="#id/actConnect2_btn_connect"
but at run time when the connect-button is visible the text view appears below it, and if pair-button is visible it overlap
how to display the textview below both buttons?
Note: i know that i can use android:layout:marginTop but i want to solve it without it
code:
<Button
android:id="#+id/actConnect2_btn_pair"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/actConnect2_tv_label_devClass"
android:layout_centerInParent="true"
android:text="#string/str_pair"/>
<Button
android:id="#+id/actConnect2_btn_connect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/str_connect"
android:layout_below="#+id/actConnect2_tv_label_devClass"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/actConnect2_tv_label_uuids"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/actConnect2_btn_connect"
android:text="Service's UUID: ">
</TextView>
<TextView
android:id="#+id/actConnect2_tv_uuids"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/actConnect2_tv_label_uuids">
</TextView>
Put both buttons in a LinearLayout then put the textview below the LinearLayout
take both button in one layout
<RelativeLayout android:id="#+id/relativeButton"
android:layout_width="wrap_content"
android:layout_below="#id/actConnect2_tv_label_devClass"
android:layout_height="wrap_content">
<Button
android:id="#+id/actConnect2_btn_pair"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/str_pair"/>
<Button
android:id="#+id/actConnect2_btn_connect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/str_connect"
android:layout_alignParentStart="true" />
</RelativeLayout>
and use this for your textview
android:layout_below="#id/relativeButton"
You have to place the buttons in a Layout (any type and arrange them accordingly)
Assign an ID to that layout.
Place the textView below that layout ID.

Actionbar custom style with title highlight on clicked

I have a quick question regarding custom style navigation in the action bar.
I have used this code to create a custom title layout:
ActionBar ab = getActionBar();
ab.setDisplayShowTitleEnabled(false);
ab.setDisplayShowCustomEnabled(true);
View customTitle = getLayoutInflater().inflate(R.layout.custom_title, null);
ab.setCustomView(customTitle);
which looks like this:
But when I click the navigate up button, only the icon and the indicator highlight... like this:
I'm looking for a way to get the whole title clickable, but with the custom layout. Is this possible?
For reference here is my actionbar layout XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Ferries"
android:textSize="20sp"
android:textColor="#FFF"
android:id="#+id/actionbar_title_depart" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""
android:textSize="10sp"
android:textColor="#FFF"
android:id="#+id/actionbar_title_arrive" />
</LinearLayout>
Thanks for taking a look, and I look forward to hear some suggestions!

Dynamic Title in XML layout Android

In my application i am getting the Title from xml code , so i have the titles in ArrayList and can set them to title bar in XML layout! but as you see in a picture its not shown correctly because of the number of words or size...i want to have the title in this size but in correct order , no problem for showing it as a half ! so actually how i can change the XML code to have title in center in same size?
and this is my XML code:
<ImageView
android:id="#+id/headerBar"
android:background="#drawable/header"
android:contentDescription = "#string/headerBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/navigation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:paddingBottom="10dp"
android:gravity="center"
android:text="#string/naviText"
android:textColor="#FFFFFF"
android:textSize="20dp"
android:textStyle="bold" />
<ImageView
android:id="#+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="14dp"
android:paddingBottom="10dp"
android:background="#drawable/back1"
android:contentDescription="#string/backBtn" />
the navigation goes for title bar !
What's the containing ViewGroup? FrameLayout?
Anyways, I would consider a different approach. I would lean more towards a top layout like a LinearLayout (horizontal) or RelativeLayout. Use the header image as its background, and then put the divider below it. This way, you can wrap_content your TextView

Categories

Resources