下面列出了android.widget.Button#requestFocus ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_backup, container, false);
view.findViewById(R.id.btnRestoreBackup).setOnClickListener(this);
Button btnSaveBackup = view.findViewById(R.id.btnSaveBackup);
btnSaveBackup.setOnClickListener(this);
btnSaveBackup.requestFocus();
etFilePath = view.findViewById(R.id.etPathBackup);
PathVars pathVars = PathVars.getInstance(view.getContext());
pathBackup = pathVars.getDefaultBackupPath();
etFilePath.setText(pathBackup);
etFilePath.setOnClickListener(this);
appDataDir = pathVars.getAppDataDir();
return view;
}
@Override
protected void showDialog(Bundle state) {
super.showDialog(state);
AlertDialog alertDialog = (AlertDialog) getDialog();
if (alertDialog == null) {
return;
}
View clear = alertDialog.findViewById(R.id.clear);
clear.setOnClickListener(clearButtonClickListener);
alertDialog
.getButton(DialogInterface.BUTTON_POSITIVE)
.setOnClickListener(okButtonClickListener);
alertDialog.setOnKeyListener(this);
Button okButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
okButton.setFocusableInTouchMode(true);
okButton.requestFocus();
setKeyEventSource(getKeyEventSourceForCurrentKeyComboModel());
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
etLogsPath = findViewById(R.id.etLogsPath);
etLogsPath.setOnClickListener(this);
Button btnSaveLogs = findViewById(R.id.btnSaveLogs);
btnSaveLogs.setOnClickListener(this);
btnSaveLogs.requestFocus();
SwitchCompat swRootCommandsLog = findViewById(R.id.swRootCommandsLog);
swRootCommandsLog.setChecked(new PrefManager(this).getBoolPref("swRootCommandsLog"));
swRootCommandsLog.setOnCheckedChangeListener(this);
Handler mHandler = new Handler();
PathVars pathVars = PathVars.getInstance(this);
appDataDir = pathVars.getAppDataDir();
busyboxPath = pathVars.getBusyboxPath();
pathToSaveLogs = pathVars.getDefaultBackupPath();
iptables = pathVars.getIptablesPath();
appUID = new PrefManager(this).getStrPref("appUID");
br = new HelpActivityReceiver(mHandler, appDataDir, pathToSaveLogs);
modulesStatus = ModulesStatus.getInstance();
if (modulesStatus.isRootAvailable()) {
IntentFilter intentFilter = new IntentFilter(RootExecService.COMMAND_RESULT);
LocalBroadcastManager.getInstance(this).registerReceiver(br, intentFilter);
}
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Button selectDirButton = findViewById(R.id.button_lbs_select_dir);
selectDirButton.setOnClickListener(v -> selectBackupDir());
selectDirButton.requestFocus(); //TV fix
}
private void initializeUi() {
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
// Get the Layoutelements
mBtnConnect = (Button) findViewById(R.id.btnConnect);
mBtnConnect.setOnClickListener(oclConnect);
mBtnConnect.requestFocus();
mBtnClementine = (ImageButton) findViewById(R.id.btnClementineIcon);
mBtnClementine.setOnClickListener(oclClementine);
// Setup the animation for the Clementine icon
mAlphaDown = new AlphaAnimation(1.0f, 0.3f);
mAlphaUp = new AlphaAnimation(0.3f, 1.0f);
mAlphaDown.setDuration(ANIMATION_DURATION);
mAlphaUp.setDuration(ANIMATION_DURATION);
mAlphaDown.setFillAfter(true);
mAlphaUp.setFillAfter(true);
mAlphaUp.setAnimationListener(mAnimationListener);
mAlphaDown.setAnimationListener(mAnimationListener);
mAnimationCancel = false;
// Ip and Autoconnect
mEtIp = (AutoCompleteTextView) findViewById(R.id.etIp);
mEtIp.setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
mEtIp.setThreshold(3);
// Get old ip and auto-connect from shared prefences
mEtIp.setText(mSharedPref.getString(SharedPreferencesKeys.SP_KEY_IP, ""));
mEtIp.setSelection(mEtIp.length());
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.select_dialog_item, mKnownIps.toArray(new String[0]));
mEtIp.setAdapter(adapter);
// Get the last auth code
mAuthCode = mSharedPref.getInt(SharedPreferencesKeys.SP_LAST_AUTH_CODE, 0);
}
private static void focusCancelButton(AlertDialog alertDialog) {
Button cancelButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
cancelButton.setFocusableInTouchMode(true);
cancelButton.requestFocus();
}