我使用来自官方android开发人员论坛的代码为我的应用启用全屏模式。 我尝试删除一些标志,以在我在文本字段中键入内容时启用系统栏,但未达到所需的结果。 我使用的代码:
private int currentApiVersion;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
currentApiVersion = android.os.Build.VERSION.SDK_INT;
final int flags =
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
// This work only for android 4.4+
if (currentApiVersion >= Build.VERSION_CODES.KITKAT) {
getWindow().getDecorView().setSystemUiVisibility(flags);
// Code below is to handle presses of Volume up or Volume down.
// Without this, after pressing volume buttons, the navigation bar will
// show up and won't hide
final View decorView = getWindow().getDecorView();
decorView
.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
decorView.setSystemUiVisibility(flags);
}
}
});
}}
@SuppressLint("NewApi")
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (currentApiVersion >= Build.VERSION_CODES.KITKAT && hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
现在看起来像这样
但是我需要这样
带有底部系统栏,当我单击“编辑”时可以隐藏键盘。
答案 0 :(得分:0)
每当用户输入或离开编辑文本时,使用Focus更改侦听器更改标志。或者,每当用户单击二者时,都可以使用Click侦听器更改标志。您也可以同时使用。以下是两个侦听器的示例代码。
emailEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
// Got Focus
// Add your code to execute when cursor enters in your edittext
}else{
// Lost the Focus
}
}
});
emailEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// User just clicked on your edit view
}
});
如果要在用户键入内容时更改状态,则可以使用“文本更改”侦听器。
emailEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
/*
Called before the changes have been applied to the text.
The charSequence parameter is the text before any change is applied.
The start parameter is the position of the beginning of the changed part in the text.
The count parameter is the length of the changed part in the s sequence since the start position.
And the after parameter is the length of the new sequence which will replace the part of the s sequence from start to start+count.
You must not change the text in the TextView from this method (by using myTextView.setText(String newText)).
*/
}
@Override
public void onTextChanged(CharSequence charSequence, int start, int count, int after) {
/*
Similar to the beforeTextChanged method but called after the text changes.
The charSequence parameter is the text after changes have been applied.
The start parameter is the same as in the beforeTextChanged method.
The count parameter is the after parameter in the beforeTextChanged method.
And the before parameter is the count parameter in the beforeTextChanged method.
You must not change the text in the TextView from this method (by using myTextView.setText(String newText)).
*/
}
@Override
public void afterTextChanged(Editable editable) {
/*
You can change the text in the TextView from this method.
/!\ Warning: When you change the text in the TextView, the TextWatcher will be triggered again, starting an infinite loop. You should then add like a boolean _ignore property which prevent the infinite loop.
*/
}
});