How to get cart badge in kotlin fragment? - android

I have already created a custom layout for badge counter and on inflating menu my cart icon is not working my codes are below.
cart Item Layout
<FrameLayout
style="?attr/actionButtonStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:background="?attr/selectableItemBackground"
android:clipToPadding="false"
android:focusable="true">
<ImageView
android:id="#+id/badge_icon_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/ic_cart"/>
<TextView
android:id="#+id/cart_badge_text_view"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="right|end|top"
android:layout_marginEnd="-5dp"
android:layout_marginRight="-5dp"
android:layout_marginTop="3dp"
android:background="#drawable/badge_cart_bg"
android:gravity="center"
android:padding="3dp"
android:textColor="#android:color/white"
android:text="0"
android:textSize="10sp"/>
toolbar menu
<item android:id="#+id/cart"
android:title=""
app:showAsAction="always"
app:actionLayout="#layout/custom_cart_item_layout"
android:icon="#drawable/ic_cart"/>
Code in fragment
code

Try this once-
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
...
myToolbar.inflateMenu(R.menu.sample_menu)
myToolbar.setOnMenuItemClickListener {
when (it.itemId) {
R.id.action_settings -> {
// Navigate to settings screen
true
}
R.id.action_done -> {
// Save profile changes
true
}
else -> false
}
}
}
}
for more details please find official link

In the onCreate of your fragment, enable options menu by calling
setHasOptionsMenu(true)
Do this in the fragment's oncreate not in the parent activity

Related

overriding onNavigationItemSelected stops navigation to fragments on item click in drawerLayout

overriding onNavigationItemSelected stops navigation component functionality of opening fragments on item click, instead it calls onNavigationItemSelected and nothing else happens.
navigation view setup called in on create
private fun setupNavigationDrawer(){
NavigationUI.setupWithNavController(binding.navigationView,navHostFragment.findNavController())
binding.navigationView.setNavigationItemSelectedListener(this)
}
activity
class MainActivity : AppCompatActivity(),NavigationView.OnNavigationItemSelectedListener
onNavigationItemSelected
override fun onNavigationItemSelected(item: MenuItem): Boolean {
if(binding.mainActivityRootView.isDrawerOpen(GravityCompat.END)){
binding.mainActivityRootView.closeDrawer(GravityCompat.END)
}
else if(binding.mainActivityRootView.isDrawerOpen(GravityCompat.START)){
binding.mainActivityRootView.closeDrawer(GravityCompat.START)
}
return true
}
Navigation view xml
<com.google.android.material.navigation.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:menu="#menu/menu_home_navigation_drawer"
android:paddingStart="15dp"
android:paddingEnd="15dp"
app:headerLayout="#layout/layout_navigation_drawer_header"
app:itemIconTint="#color/lipstick"
android:layout_gravity="end"
app:drawerLayoutCornerSize="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" >
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom"
android:layout_marginBottom="40dp"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_main_blue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="#color/lipstick" />
<TextView
android:id="#+id/textView41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/montserratmedium"
android:text="Version IMPLEMENT"
android:textColor="#color/pinkish_grey"
android:textSize="10sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.navigation.NavigationView>
i have set menu item id as navigation fragment id and it works without the onNavigationItemSelected being set i also have navigation view below fragment container in xml
i tried to
-change return value onNavigationItemSelected
-setting up onNavigationItemSelected listener before setupWithNavController which results in the listener not getting called at all
In the end i solved it by manually opening fragments
from
override fun onNavigationItemSelected(item: MenuItem): Boolean {
if(binding.mainActivityRootView.isDrawerOpen(GravityCompat.END)){
binding.mainActivityRootView.closeDrawer(GravityCompat.END)
}
else if(binding.mainActivityRootView.isDrawerOpen(GravityCompat.START)){
binding.mainActivityRootView.closeDrawer(GravityCompat.START)
}
return true
}
to
override fun onNavigationItemSelected(item: MenuItem): Boolean {
if(binding.mainActivityRootView.isDrawerOpen(GravityCompat.END)){
binding.mainActivityRootView.closeDrawer(GravityCompat.END)
}
else if(binding.mainActivityRootView.isDrawerOpen(GravityCompat.START)){
binding.mainActivityRootView.closeDrawer(GravityCompat.START)
}
when(item.itemId){
else ->{
NavigationUI.onNavDestinationSelected(item,navHostFragment.findNavController())
}
}
return true
}

Add an extra button in AlertDialog in DialogFragment

I have a custom DialogFragment, and was trying to use AlertDialog in onCreateDialog(). The AlertDialog only has title, singleChoiceItem, positiveButton, etc. But I would like to add an extra button on the top left to be a back button that I could add a onClickListener. How could I do that? Thanks!
You can create your own xml file with a button on left corner.Now that you have created an Xml file as Custom layout. inflate that file using below code
AlertDialog.Builder builder
= new AlertDialog.Builder(this);
builder.setTitle("Name");
// set the custom layout
final View customLayout
= getLayoutInflater()
.inflate(
R.layout.custom_layout,
null);
builder.setView(customLayout);
After creating your own custom layout set a listener for the button that you have positioned on top left corner in xml by calling findViewByID on Dialog and then calling closeButton.setOnClickListener.
You can use custom dialog. Your Kotlin Class:
class CustomDialog(var c: Activity) : Dialog(c), View.OnClickListener {
var d: Dialog? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(R.layout.dailog_custom)
}
override fun onClick(v: View) {
}
}
XML file of dialog:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginHorizontal="#dimen/extra_padding"
android:background="#drawable/bg_ripple_secondary_variant_less_rounded"
android:padding="20dp">
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:textStyle="bold"
android:textSize="#dimen/_12sdp"
android:textColor="#color/red"
android:text="Title" />
<TextView
android:id="#+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/less_padding"
app:layout_constraintTop_toBottomOf="#id/tvTitle"
app:layout_constraintStart_toStartOf="parent"
android:text="Your Message"
android:textStyle="bold"
android:textSize="#dimen/_12sdp"
android:textColor="?attr/colorOnPrimary" />
<TextView
android:id="#+id/btnYes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/tvMessage"
app:layout_constraintEnd_toEndOf="parent"
android:padding="#dimen/fab_padding"
android:textColor="#color/red"
android:text="#string/yes" />
<TextView
android:id="#+id/btnNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#id/tvMessage"
app:layout_constraintEnd_toStartOf="#id/btnYes"
android:padding="#dimen/fab_padding"
android:textColor="?attr/colorOnPrimary"
android:text="#string/no" />
</androidx.constraintlayout.widget.ConstraintLayout>

How to create dialog which ask for pin if it is correct a following operation will be done

This code is where I am creating Alert dialog. whenever I press ok it crashes .password_dialog has 1 editText and 2 buttons.
private fun passwordCheck(position: Int){
val view=LayoutInflater.from(requireContext()).inflate(R.layout.password_dialog,null,false)
val builder=AlertDialog.Builder(requireContext())
with(builder){
setTitle("Enter your Pin")
setPositiveButton("Ok"){dialog,which->
if(pin_text.text.toString()=="1234"){
Toast.makeText(requireContext(),"Right Pin",Toast.LENGTH_LONG).show()
}
else{
pin_text.requestFocus()
pin_text.error="Incorrect"
}
}
setCancelable(false)
setNegativeButton("Cancel"){dialog,which->
dialog.dismiss()
}
setView(view)
show()
}
}
Create a layout with the view, for example, an EditText that only accepts numbers and two buttons, accept or cancel.
Then inflate the view
val view = LayoutInflater.from(context).inflate(R.id.layout, null, false)
Then with that view you get the reference of the buttons and the EditText with
val button = view.findViewById<Button>(R.id.button)
//I'm not going to declare all views, but assuming you already did.
button.setOnClickListener {
if (editText.text.toString.toInt() == 1234 //your correct pin) {
//CORRECT PIN TODO
} else {
editText.requestFocus()
editText.error = "Incorrect pin"
}
}
Then create the dialog and add that view to it
AlertDialog.Builder(context).setView(view).create().show()
Do not add the validation methods in the accept button of the dialog.
They are what are declared as follows.
setPositiveButton("Accept"){diálog, which -> }
This is the way by which you can create your own dialog with custom layout.
Implement your PIN UI in custom_dialog.xml and your logic in Kotlin file.
Here is example how you can create custom Dialog.
custom_dialog.xml
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
android:background="#424242">
<TextView
android:id="#+id/popup_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16sp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16sp"
android:layout_marginBottom="10dp"
android:text="Custom Dialog Box"
android:textColor="#color/white"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:id="#+id/linearLayoutOpt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16sp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16sp"
android:layout_marginBottom="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/popup_dialog">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">
<TextView
android:id="#+id/no_opt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingTop="8dp"
android:paddingRight="8dp"
android:paddingBottom="18dp"
android:text="No"
android:textStyle="bold"
android:textAllCaps="false"
android:textColor="#color/white" />
<Space
android:layout_width="32sp"
android:layout_height="12sp" />
<TextView
android:id="#+id/yes_opt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingTop="8dp"
android:paddingRight="8dp"
android:paddingBottom="18dp"
android:text="Yes"
android:textStyle="bold"
android:textAllCaps="false"
android:textColor="#color/white" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
showDialog()
}
private fun showDialog() {
val customDialog = Dialog(this)
customDialog.setContentView(R.layout.custom_dialog)
customDialog.window?.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
val yesBtn = customDialog.findViewById(R.id.yes_opt) as TextView
val noBtn = customDialog.findViewById(R.id.no_opt) as TextView
yesBtn.setOnClickListener {
//Do something here YOUR LOGIC
customDialog.dismiss()
}
noBtn.setOnClickListener {
customDialog.dismiss()
}
customDialog.show()
}
}
example app screenshot

Handling click events in android kotlin: setOnClickListener only works when double-clicked

I have a button in a DialogFragment to go back to another activity. But it only works when double-clicked. I'm running out of ideas. In my XML file, I've already tried the following (combined in different ways, but none of them worked)
My whole fragment XML file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="600dp"
android:layout_height="500dp"
android:layout_gravity="center"
android:background="#drawable/bg_rounded_white"
android:gravity="center"
android:orientation="vertical"
android:padding="#dimen/vertical_margin">
<TextView
android:id="#+id/tv_payment_done_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/vertical_margin"
android:gravity="center_horizontal"
android:text="#string/payment_approved_title"
android:textColor="#color/bg_color"
android:textSize="#dimen/text_large"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_payment_message"
android:layout_width="550dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/vertical_margin"
android:gravity="center_horizontal"
android:minHeight="100dp"
android:text="Payment done!"
android:textColor="#color/black_overlay"
android:textSize="#dimen/text_medium"
android:textStyle="normal" />
<LinearLayout
android:layout_width="600dp"
android:layout_height="80dp"
android:layout_marginTop="46dp"
android:clickable="false"
android:focusable="false"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/rpv_btn_no_payment_done"
android:layout_width="250dp"
android:layout_height="?android:attr/actionBarSize"
android:background="#drawable/bg_rounded_light_blue"
android:duplicateParentState="true"
android:text="#string/txt_btn_no"
android:textAllCaps="false"
android:textColor="#color/white_text_color"
android:textSize="#dimen/text_medium"
android:textStyle="bold"
android:visibility="gone" />
<Button
android:id="#+id/rpv_btn_yes_payment_done"
android:layout_width="250dp"
android:layout_height="?android:attr/actionBarSize"
android:layout_marginLeft="#dimen/vertical_margin"
android:background="#drawable/bg_rounded_light_blue"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:focusedByDefault="true"
android:text="#string/txt_btn_exit"
android:textAllCaps="false"
android:textColor="#color/white_text_color"
android:textSize="#dimen/text_medium"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
As for my DialogFragment, I've tried to put my setOnClickListener inside the onViewCreated() method, and then inside the onStart() and after inside the onResume() methods. It keeps working only when double-clicked. I also have a timer that makes the dialog disappear after 10 secs and then it leads me to the activity I want anyway, so it isn't so much of a problem, but I really need and want to fix it. If I set the timer to 5 secs or lower, of course, it gives the impression that the button works when clicked once, but it actually doesn't.
class PaymentDoneDialogFragment : DialogFragment() {
private lateinit var mYesBtn: Button
private lateinit var mActionYes: () -> Unit
override fun onViewCreated(view: View, #Nullable savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
dialog.setCanceledOnTouchOutside(false)
dialog.window.requestFeature(Window.FEATURE_NO_TITLE)
dialog.window.setDimAmount(.85f)
dialog.window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
dialog.setCancelable(false)
dialog.setCanceledOnTouchOutside(false)
dialog.window.decorView.systemUiVisibility = activity?.window!!.decorView.systemUiVisibility
dialog.window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
mDialogTitle = view.find(R.id.tv_payment_done_title)
if (mTitle != null) {
mDialogTitle.text = mTitle
}
mYesBtn = view.find(R.id.rpv_btn_yes_payment_done)
if (mYesTitle != null) {
mYesBtn.text = mYesTitle
}
mYesBtn.setOnClickListener {
if (mMessage == null) {
(activity as PaymentActivity).nextScreensaverActivity()
} else {
mActionYes()
}
activity?.supportFragmentManager?.beginTransaction()?.remove(this)?.commit()
}
if (mMessage != null) {
mMessageTextView = view.find(R.id.tv_payment_message)
mMessageTextView?.text = mMessage
mNoBtn = view.find(R.id.rpv_btn_no_payment_done)
if (mNoTitle != null)
mNoBtn.text = mNoTitle
mNoBtn.visibility = View.VISIBLE
mNoBtn.setOnClickListener {
mActionNo()
activity?.supportFragmentManager?.beginTransaction()?.remove(this)?.commit()
}
}
}
Does anyone have some clue?
You should remove android:clickable="false" and android:focusable="false" from LinearLayout child

Showing Android Wear style AlertDialog

I'm looking for a way to recreate the alert dialog in the Setting application of Android Wear:
Which is swipe to dismissable.
But instead, what I got is this:
Just a barebone Android dialog. How can I show the AlertDialog in the Settings.apk style? (Which I think must be default for Android Wear application)
I found no default way to do this, also setting a custom view to an AlertDialog did not look good. You can still try though, maybe a different Theme works.
What I did was create a new Activity and create my own layout which looks like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout
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:gravity="center"
android:orientation="vertical"
android:padding="10dp"
app:layout_box="all">
<TextView
android:id="#+id/tv_longtext"
android:layout_width="match_parent"
android:layout_height="0sp"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:gravity="bottom"
android:padding="5sp"
android:text="Ambient screen reduces battery life."
android:textSize="16sp" />
<TextView
android:id="#+id/tv_question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:gravity="center_horizontal|top"
android:paddingBottom="15sp"
android:paddingTop="5sp"
android:text="Turn on?"
android:textSize="18sp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5sp">
<android.support.wearable.view.CircledImageView
android:id="#+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:src="#drawable/ic_cross"
app:circle_color="#AFAFAF"
app:circle_radius="25dp"
app:circle_radius_pressed="20dp" />
<android.support.wearable.view.CircledImageView
android:id="#+id/btn_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:src="#drawable/ic_tick"
app:circle_color="#0EB695"
app:circle_radius="25dp"
app:circle_radius_pressed="20dp" />
</FrameLayout>
</LinearLayout>
</android.support.wearable.view.BoxInsetLayout>
It looks just like the confirmation screen from the settings. Maybe it still needs some tweaks, but I think this is the way to go.
I had a similar problem and indeed I didn't find a default way to do this. I tried to use AlertDialogs for WearOs and they don't look well, because even if you pass them a custom view, the AlertDialog class crops the layout in some unexpected ways.
How I ended up solving the problem is using the Dialog class (AlertDialog's parent class) and passing it a custom view. The Dialog class doesn't alter the layout and you can attach the dialog to an activity's lifespan (which is the idea of dialogs, creating a custom activity doesn't fit with this requirement).
So you could create a function like this inside your activity:
private void showDialog() {
Dialog dialog = new Dialog(this);
View myLayout = getLayoutInflater().inflate(R.layout.my_layout_id, null);
Button positiveButton = myLayout.findViewById(R.id.positive_button);
positiveButton.setOnClickListener(
v -> {
/* Your action on positive button clicked. */
}
);
Button negativeButton = myLayout.findViewById(R.id.negative_button);
negativeButton.setOnClickListener(
v -> {
/* Your action on negative button clicked. */
}
);
dialog.setContentView(myLayout);
dialog.show();
}
I created a similar fragment with custom layout like this:
Kotlin code:
/**
* Created by nmbinh87#gmail.com on 4/12/21.
*/
class ConfirmationDialog private constructor() : DialogFragment(R.layout.confirmation_dialog) {
var listener: Listener? = null
var longMessage: String = ""
var shortMessage = ""
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
tv_longtext.text = longMessage
tv_question.text = shortMessage
tv_longtext.visibility = if (longMessage.isEmpty()) View.GONE else View.VISIBLE
tv_question.visibility = if (shortMessage.isEmpty()) View.GONE else View.VISIBLE
btn_cancel.setSafeOnClickListener {
dismiss()
listener?.onCancel()
}
btn_ok.setSafeOnClickListener {
dismiss()
listener?.onConfirm()
}
}
override fun onStart() {
super.onStart()
val params = dialog?.window?.attributes
params?.width = WindowManager.LayoutParams.MATCH_PARENT
params?.height = WindowManager.LayoutParams.MATCH_PARENT
dialog?.window?.attributes = params as WindowManager.LayoutParams
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT));
}
open class Listener {
fun onCancel() {
}
open fun onConfirm() {
}
}
companion object {
fun show(
fm: FragmentManager,
longMessage: String = "",
shortMessage: String = "",
listener: Listener
) {
val fragment = ConfirmationDialog()
fragment.longMessage = longMessage
fragment.shortMessage = shortMessage
fragment.listener = listener
fragment.show(fm, fm::class.simpleName)
}
}
}
Layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout 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:background="#color/colorPrimaryDark"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp"
app:layout_box="all">
<TextView
android:id="#+id/tv_longtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed"
android:gravity="center"
android:padding="5sp"
android:textColor="#color/white"
android:textSize="16sp"
tools:text="Ambient screen reduces battery life." />
<TextView
android:id="#+id/tv_question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-condensed"
android:layout_weight="1"
android:gravity="center"
android:paddingTop="5sp"
android:paddingBottom="15sp"
android:textColor="#color/white"
android:textSize="18sp"
tools:text="Turn on?" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5sp">
<android.support.wearable.view.CircledImageView
android:id="#+id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:src="#drawable/ic_cc_clear"
app:circle_color="#AFAFAF"
app:circle_radius="25dp"
app:circle_radius_pressed="20dp" />
<android.support.wearable.view.CircledImageView
android:id="#+id/btn_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:src="#drawable/ic_cc_checkmark"
app:circle_color="#0EB695"
app:circle_radius="25dp"
app:circle_radius_pressed="20dp" />
</FrameLayout>
</LinearLayout>
</android.support.wearable.view.BoxInsetLayout>
Usage:
ConfirmationDialog.show(
childFragmentManager,
"",
"Turn alarm off?",
object : ConfirmationDialog.Listener() {
override fun onConfirm() {
super.onConfirm()
turnAlarm(false)
}
})

Categories

Resources