【发布时间】:2015-09-23 10:50:54
【问题描述】:
我正在尝试了解应用是否知道或可以告知您何时访问快速设置。
我有一组按钮用作选项卡(在Fragment 中,在CardView) 中,当我拉下快速设置时,按钮会失去其状态。我已经尝试了几种机制来解决它,但找不到路。
按钮使用
.setOnTouchListener(new View.OnTouchListener() { ... }
而不是onClick listener。
当我尝试在显示对话框之前设置按钮的状态时,如果我在对话框关闭后设置状态,我会得到相同的效果
public void onClick(DialogInterface dialog, int which) { ... }
然后我可以获得所需的行为。
我在对话方式方面遗漏了一些知识,因此 quick settings 导致基础视图被更新或通知更改。
谁能帮忙。
更新:
按钮xml如下
<Button
android:id="@+id/fs_btn_tab_month"
style="@style/DefaultButtonText"
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_margin="0dp"
android:background="@drawable/button_default_bg"
android:gravity="center|center_vertical"
android:text="@string/fs_btn_tab_month"
android:textColor="@color/button_text_color" />
并且 button_default_bg 是
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<solid
android:color="@color/text_white" />
<stroke
android:width="1dp"
android:color="@color/text_white" />
<corners
android:radius="1dp" />
</shape>
</item>
<item>
<shape>
<solid
android:color="@color/background" />
<stroke
android:width="1dp"
android:color="@color/text_white" />
<corners
android:radius="1dp" />
</shape>
</item>
</selector>
就 setOnClickListener() 与 setOnTouchListener() 而言,我需要设置按钮的状态,使其看起来像一个选项卡,并且能够从片段的其他地方执行此操作,但我找不到方法使用 setOnClickListener 来做到这一点。
看起来像这样
当我说失去它的状态时,它会变成蓝色背景。
我将“状态”设置如下
mDaySelectedButton.setPressed(false);
mMonthSelectedButton.setPressed(true);
mMonthSelectedButton.setElevation(0f);
mYearSelectedButton.setPressed(false);
一切正常,除了快速设置下拉问题。
【问题讨论】:
-
你所说的“失去它的状态”是什么意思,这种状态损失是什么样子或表现出来的?当您只关注点击时,是否有使用 touchListener 的理由?
-
摩羯座,在上面添加了更多细节。
-
我猜在您的屏幕截图中,“月”按钮处于pressed_state,因此具有白色背景?并且当从android下拉通知中心或快速设置面板时,它返回到“未按下”的外观(紫色/蓝色背景)?
-
这正是行为
-
我假设按下的视图在失去焦点时会失去它们的状态,当应用程序被通知中心/快速设置覆盖时会发生什么。您是否尝试过使用“已选择”状态?
标签: android button dialog android-alertdialog