Android 如何去除Launcher上默认的google search bar?
前言
欢迎大家我分享和推荐好用的代码段~~
声明
欢迎转载,但请保留文章原始出处:
CSDN:http://www.csdn.net
雨季o莫忧离:http://blog.csdn.net/luckkof
正文
请参考如下改法:
1. Launcher2\res\layout\qsb_bar.xml中,
<include android:id="@+id/qsb_search_bar"
layout="@layout/search_bar"
android:visibility="gone" /> //加入 android:visibility="gone"
2. Launcher2\src\com\android\launcher2\SearchDropTargetBar.java 中
onFinishInflate() 方法内,将mQSBSearchBarFadeInAnim相关的部分作如下修改:
mQSBSearchBarFadeInAnim = ObjectAnimator.ofFloat(mQSBSearchBar, "alpha", 0f); //最后一个参数改为 0f, 原来是 1f
mQSBSearchBarFadeInAnim.setDuration(sTransitionInDuration);
mQSBSearchBarFadeInAnim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
mQSBSearchBar.setVisibility(View.INVISIBLE); //参数改为 View.INVISIBLE, 原来是 View.VISIBLE
3. 仍然是此 java 文件,将showSearchBar() 方法作如下修改:
public void showSearchBar(boolean animated) {
if (LauncherLog.DEBUG) LauncherLog.d(TAG, "(SearchDropTargetBar)showSearchBar animated = " + animated);
cancelAnimations();
if (animated) {
mQSBSearchBarFadeInAnim.start();
} else {
mQSBSearchBar.setVisibility(View.INVISIBLE); //参数改为:View.INVISIBLE
mQSBSearchBar.setAlpha(0f); //参数改为 0f.
}
mIsSearchBarHidden = false;
}
}
});
JB:
1. Launcher2\res\layout\qsb_bar.xml中,
<include android:id="@+id/qsb_search_bar"
layout="@layout/search_bar"
android:visibility="gone" /> //加入 android:visibility="gone"
2. packages\apps\Launcher2\res\layout-port\launcher.xml
<com.android.launcher2.DrawableStateProxyView
android:id="@+id/voice_button_proxy"
android:layout_width="80dp"
android:layout_height="@dimen/qsb_bar_height"
android:layout_gravity="top|right"
android:clickable="false" //modify this value to false
onClick="onClickVoiceButton"
android:importantForAccessibility="no"
launcher:sourceViewId="@+id/voice_button" />
3. Launcher2\src\com\android\launcher2\SearchDropTargetBar.java 中
onFinishInflate() 方法内,将mQSBSearchBarAnim 相关的部分作如下修改:
// Create the various fade animations
if (mEnableDropDownDropTargets) {
mDropTargetBar.setTranslationY(-mBarHeight);
mDropTargetBarAnim = ObjectAnimator.ofFloat(mDropTargetBar, "translationY",
-mBarHeight, 0f);
mQSBSearchBarAnim = ObjectAnimator.ofFloat(mQSBSearchBar, "translationY", -mBarHeight,
-mBarHeight); //modify 3rd para to -mBarHeight
} else {
mDropTargetBar.setAlpha(0f);
mDropTargetBarAnim = ObjectAnimator.ofFloat(mDropTargetBar, "alpha", 0f, 1f);
mQSBSearchBarAnim = ObjectAnimator.ofFloat(mQSBSearchBar, "alpha", 0f, 0f); //modify 3rd para to 0f;
}
4. 仍然是这只 java 文件,将showSearchBar 方法作如下修改:
public void showSearchBar(boolean animated) {
if (!mIsSearchBarHidden) return;
if (animated) {
prepareStartAnimation(mQSBSearchBar);
mQSBSearchBarAnim.reverse();
} else {
mQSBSearchBarAnim.cancel();
if (mEnableDropDownDropTargets) {
mQSBSearchBar.setTranslationY(0);
} else {
mQSBSearchBar.setAlpha(0f); //参数改为 0f;
}
}
mIsSearchBarHidden = false;
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。