这是我的第一个问题,如果我做错了,请原谅我。
问题是: 我有活动“ FirstConfig.kt”。当用户单击特定按钮时,我正在显示具有生物特征认证的片段。 Fragment在“顶部”,因此父级活动在他的“后面”并作为背景。如何禁用具有活动但没有片段的用户干扰,以允许单击生物识别提示中的“取消”
FirstConfig.kt中的功能
private fun ShowBiometricPrompt() {
supportFragmentManager.beginTransaction()
.setCustomAnimations(R.anim.slide_up, R.anim.slide_down)
.add(
R.id.main_first_config,
SmallBiometricAuthenticate::class.java.newInstance()
).commit()
}
我尝试这个
window.setFlags(
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
但是,这会阻塞整个活动,并且用户无法单击“取消”。 有人可以帮我吗?
@EDIT
是的。我也想让片段可触摸而活动不可触摸
ActivityLayout(此布局的主要部分是ConstraintLayout,但是stackoverflow将我的这部分代码删除了)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="@+id/first_config_layout"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Przeprowadzimy teraz krótką konfigurację, aby dostować aplikację do Twoich oczekiwań"
android:textAlignment="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="5dp"
android:text="Powiadomienia"
android:textAlignment="center"
android:textColor="#111111"
android:textSize="18dp"
android:textStyle="bold" />
<View
android:id="@+id/bottom_belk"
android:layout_width="80dp"
android:layout_height="2dp"
android:background="#111111"
android:paddingLeft="10dp"
android:paddingRight="10dp"></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="20dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="center"
android:text="Zmiany w grafiku" />
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="center"
android:text="Nowa ocena" />
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="center"
android:text="Zbliżająca się płatność" />
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="center"
android:text="Nowa wiadomość" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:orientation="vertical">
<Switch
android:id="@+id/graphic_nottification"
android:layout_width="50dp"
android:layout_height="40dp"
android:onClick="RegisterChangeOfPushSwitch" />
<Switch
android:id="@+id/mark_nottification"
android:layout_width="50dp"
android:layout_height="40dp"
android:onClick="RegisterChangeOfPushSwitch" />
<Switch
android:id="@+id/payment_nottification"
android:layout_width="50dp"
android:layout_height="40dp"
android:onClick="RegisterChangeOfPushSwitch" />
<Switch
android:id="@+id/message_nottification"
android:layout_width="50dp"
android:layout_height="40dp"
android:onClick="RegisterChangeOfPushSwitch" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="5dp"
android:text="Zabezpieczenie"
android:textAlignment="center"
android:textColor="#111111"
android:textSize="18dp"
android:textStyle="bold" />
<View
android:layout_width="80dp"
android:layout_height="2dp"
android:background="#111111"
android:paddingLeft="10dp"
android:paddingRight="10dp"></View>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="horizontal"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:weightSum="5">
<ImageView
android:id="@+id/security_biometric"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_weight="1"
android:background="@drawable/black_border"
android:padding="10dp"
android:src="@drawable/ic_fingerprint_black_"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1" />
<ImageView
android:id="@+id/security_disable"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_weight="1"
android:background="@drawable/black_border"
android:padding="10dp"
android:src="@drawable/ic_no_screen_security"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="1" />
<ImageView
android:id="@+id/security_pin"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_weight="1"
android:background="@drawable/black_border"
android:padding="10dp"
android:src="@drawable/ic_fiber_pin_black" />
</LinearLayout>
</LinearLayout>
他是XML片段(同样的情况。这种情况是FrameLayout)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_corners_small_biometric"
android:layout_gravity="bottom"
android:paddingTop="15dp"
android:orientation="vertical">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/ic_fingerprint_black_"
android:layout_gravity="center"
android:id="@+id/finger_print_icon"
android:background="#ffffff"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_marginTop="15dp"
android:textSize="15dp"
android:text="Zidentyfikuj się"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cancel_auth"
android:text="Anuluj"
android:textAlignment="center"
android:textColor="#0055A5"
android:textStyle="bold"
android:textSize="22dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"/>
</LinearLayout>
就是这样。当我设置标志NOT_TOUCHABLE时,用户无法取消身份验证(单击“ Anuluj”) screen_with_autohrization
@ EDIT2
谢谢@РСИТ_
我将生物识别提示作为活动对话框。为了从FingerPrintAPI获得callbak,我创建了接口“ FingerPrintCallback”。将他实施到FirstConfigActivity中,并在具有相应活动上下文的BiometricDialog中返回。
非常感谢您的帮助:)
答案 0 :(得分:0)
只需将“活动”用作对话框。
分步操作:
使用bio-detect和清单创建活动:
<activity android:name=".BioActivity" android:theme="@android:style/Theme.Dialog"/>
在创建的活动xml(BioActivity.xml)中,将标签android:excludeFromRecents="true"
添加到根目录(LinearLayout或其他):
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_height="match_parent"
tools:context=".BioActivity"
android:excludeFromRecents="true"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
在对话框活动的java类文件中,将此代码放在onCreate()
之后的setContentView();
方法中
public class BioActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bio_activity);
this.setFinishOnTouchOutside(false);
}
}
使用主要活动中的intent和startActivity()开始创建对话框活动;
答案 1 :(得分:0)
尝试使用FrameLayout
使android:clickable="true"
可点击
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_corners_small_biometric"
android:layout_gravity="bottom"
android:paddingTop="15dp"
android:orientation="vertical">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/ic_fingerprint_black_"
android:layout_gravity="center"
android:id="@+id/finger_print_icon"
android:background="#ffffff"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:layout_marginTop="15dp"
android:textSize="15dp"
android:text="Zidentyfikuj się"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cancel_auth"
android:text="Anuluj"
android:textAlignment="center"
android:textColor="#0055A5"
android:textStyle="bold"
android:textSize="22dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"/>
</LinearLayout>
</FrameLayout>
答案 2 :(得分:0)
Yes. I want too make the fragment touchable while activity is not touchable
为此,您可以通过在true
中返回onTouch
来分段使用touch事件。例如
SmallBiometricAuthenticate : View.OnTouchListener {
override fun onTouch(v: View, event: MotionEvent) {
return true
}
}
并将OnTouchListener
添加到片段根view
。