Hello everyone, this question. The drawable state_focused and state_pressed for dialogs do not work for me, as long as I try to help nothing. With the buttons, everything works fine, but for the texts it does not work. What to do?

created by java class Material Dialog.java

package biz.galamat.simpleinsta; import android.app.Dialog; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.Window; import android.widget.TextView; public class MaterialDialog extends Dialog implements View.OnClickListener { public Context mContext; public MaterialDialog(Context context) { super(context); mContext = context; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.dialog); TextView text1 = (TextView) findViewById(R.id.text1); TextView text2 = (TextView) findViewById(R.id.text2); text1.setOnClickListener(this); text2.setOnClickListener(this); } @Override public void onClick(View view) { } } 

xml file for dialogue

  <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/dialog_background_up" android:clickable="true" android:focusable="true" android:focusableInTouchMode="true" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeightSmall" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" android:paddingRight="?android:attr/listPreferredItemPaddingRight" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:text="Удалить" android:textColor="@color/dialog_listview_color" android:textSize="17sp" /> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/divider_color" /> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text2" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/dialog_background_down" android:clickable="true" android:focusable="true" android:focusableInTouchMode="true" android:gravity="center_vertical" android:minHeight="?android:attr/listPreferredItemHeightSmall" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:paddingLeft="?android:attr/listPreferredItemPaddingLeft" android:paddingRight="?android:attr/listPreferredItemPaddingRight" android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:text="Отключить уведомления" android:textColor="@color/dialog_listview_color" android:textSize="17sp" /> </LinearLayout> 

one drawable file

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@android:color/white"> <shape> <solid android:color="@android:color/white" /> <corners android:bottomLeftRadius="4dp" android:bottomRightRadius="4dp" /> </shape> </item> <item android:state_pressed="true" android:drawable="@color/dialog_on_hold_color"> <shape> <solid android:color="@color/dialog_on_hold_color" /> <corners android:bottomLeftRadius="4dp" android:bottomRightRadius="4dp" /> </shape> </item> <item android:state_selected="true" android:drawable="@color/dialog_on_hold_color"> <shape> <solid android:color="@color/dialog_on_hold_color" /> <corners android:bottomLeftRadius="4dp" android:bottomRightRadius="4dp" /> </shape> </item> </selector> 
  • one
    Change the order. item without steytov make the last. When changing the state, the first (in order) suitable item is taken, it is always the same for you, since fits any state - Yura Ivanov

1 answer 1

a linear layout wrapper helped, with the same parameters