我正在尝试将TextInputEditText设为只读,但是我快速移动了光标并触发了点击。
我尝试设置isFocusable = false
和isClickable = false
。
XML布局:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/label_address"
android:layout_marginTop="@dimen/material_layout_vertical_spacing_between_content_areas"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/input_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"/>
</com.google.android.material.textfield.TextInputLayout>
设为只读的代码:
fun TextInputEditText.disable() {
isFocusable = false
isClickable = false
}
将TextInputEditText设置为只读的正确方法或正确方法是什么?
答案 0 :(得分:3)
在android:enable="false"
中设置属性TextInputEditText
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Hints"
android:layout_marginTop="10dp"
android:layout_margin="40dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/input_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:enabled="false"
android:imeOptions="actionNext"
android:text="Hi How are you"
android:textColor="@color/colorPrimary"
android:textColorHint="@color/colorPrimary" />
</com.google.android.material.textfield.TextInputLayout>
答案 1 :(得分:1)
实现此目的的正确方法是使用TextView,您可以将其应用于EditTextStyle。但是,您不应该实现EditText并将其用作TextView,请记住,对象是为满足特定需求而设计的,因此请始终根据您要执行的操作找到最适合的对象。
答案 2 :(得分:0)
我通常使用 Param
(
[Parameter(Position=0,Mandatory=$false)]
[ValidateNotNullorEmpty()]
[Alias('cn')][String[]]$ComputerName=$Env:COMPUTERNAME,
[Parameter(Position=1,Mandatory=$false)]
[Alias('un')][String[]]$AccountName,
[Parameter(Position=2,Mandatory=$false)]
[Alias('cred')][System.Management.Automation.PsCredential]$Credential
)
$Obj = @()
$now = Get-Date
Foreach($Computer in $ComputerName)
{
If($Credential)
{
$AllLocalAccounts = Get-WmiObject -Class Win32_UserAccount -
Namespace "root\cimv2" `
-Filter "LocalAccount='$True'" -ComputerName $Computer -
Credential $Credential -ErrorAction Stop
}
else
{
$AllLocalAccounts = Get-WmiObject -Class Win32_UserAccount -Namespace "root\cimv2" `
-Filter "LocalAccount='$True'" -ComputerName $Computer -ErrorAction Stop
}
$Obj = $AllLocalAccounts | ForEach-Object {
$user = ([adsi]"WinNT://$computer/$($_.Name),user")
$pwAge = $user.PasswordAge.Value
$maxPwAge = $user.MaxPasswordAge.Value
$pwLastSet = $now.AddSeconds(-$pwAge)
# for Last Login
$adsi = [ADSI]"WinNT://$computer"
$lLogin = ($adsi.Children | where {($_.SchemaClassName -eq 'user') -and ($_.Name -eq $user.Name ) })
$lastLogin = ($lLogin.LastLogin).value
$Group= [ADSI]"WinNT://$Server/$LocalGroup,group"
$members = $Group.psbase.Invoke("Members")
$members | ForEach-Object { $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null) }
New-Object -TypeName PSObject -Property @{
'Name' = $_.Name
'Full Name' = $_.FullName
'Disabled' = $_.Disabled
'Description' = $_.Description
'Status' = $_.Status
'LockOut' = $_.LockOut
'Password Expires' = $_.PasswordExpires
'Password Last Set' = $pwLastSet
'Password Expiry Date' = $now.AddSeconds($maxPwAge - $pwAge)
'Password Required' = $_.PasswordRequired
'Account Type' = $_.AccountType
'Domain' = $_.Domain
'Password Age' = ($now - $pwLastSet).Days
'Last Login' = $lastLogin
}
}
If($AccountName)
{
Foreach($Account in $AccountName)
{
$Obj|Where-Object{$_.Name -like "$Account"}
}
}
else
{
$Obj
}
}
ref link
它可以满足您的需求吗?
答案 3 :(得分:0)
尝试将CustomerID = [[1,2],[2,3],[4,6],[6,9],3,7,2,(1,2,3),(76,5,3)]
list_of_lists =[]
list_of_tuples =[]
list_of_elements =[]
for item in CustomerID:
if type(item) is list:
list_of_lists.append(item)
elif type(item) is tuple:
list_of_tuples.append(item)
else:
list_of_elements.append(item)
或Edittext.setEnabled(false);
添加到视图中。
答案 4 :(得分:0)
为您的TextInputEditText尝试isEnabled功能。
android:editable="false"
答案 5 :(得分:0)
您可以尝试使用以下属性:
android:textIsSelectable="true"
android:inputType="none"
请注意,{strong>已弃用android:editable
。
假设您的变量名为editText
,则可以尝试以下操作:
editText.isEnabled = false
答案 6 :(得分:0)
在edittext中使用这些属性
android:clickable="false" android:cursorVisible="false" android:focusable="false" android:focusableInTouchMode="false"