Closed CrazySnail1 closed 8 years ago
我不是很理解,你说的你的布局是定义在View
上,而不是MainActivity
上,所有的布局都是View
,最终都是作用在Window
提供的DecorView
上的,你只要保证,在我们应用层可见的最上层布局就行了,如 对于Activity而言,就是 Id为 android.R.id.content
的View的下层布局就行了。
我的main_activity.xml: ` <com.zhf.t9ui.view.SearchActivityView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/search_activity_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFFFF" >
<EditText
android:id="@+id/search_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="@+id/result_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/search_edit"/>
<include layout="@layout/switch_input_tab_bar"
android:id="@+id/switch_input_tab_bar"/>
<ImageView
android:id="@+id/tab_bar_shadow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/switch_input_tab_bar"
android:layout_alignWithParentIfMissing="true"
android:background="@mipmap/tab_shadow" />
<cn.dreamtobe.kpswitch.widget.KPSwitchPanelFrameLayout
android:id="@+id/panel_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone">
<include layout="@layout/t9_panel_content"/>
<include layout="@layout/voice_panel_content"
android:visibility="gone"/>
</cn.dreamtobe.kpswitch.widget.KPSwitchPanelFrameLayout>
</com.zhf.t9ui.view.SearchActivityView>`
SearchActivityView:
public class SearchActivityView extends RelativeLayout implements IPanelHeightTarget, IPanelConflictLayout {
。。。。。。。。
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mSearchListView = (ListView) findViewById(R.id.result_list);
mSearchEdit = (EditText) findViewById(R.id.search_edit);
mPanelRoot = (KPSwitchPanelFrameLayout) findViewById(R.id.panel_root);
mBtnSoft = (RadioButton) findViewById(R.id.tab_input_soft);
mBtnT9 = (RadioButton) findViewById(R.id.tab_input_t9);
mBtnVoice = (RadioButton) findViewById(R.id.tab_input_voice);
}
public void updateChangePanelState(Activity context){
KeyboardUtil.attach(context, mPanelRoot,
// Add keyboard showing state callback, do like this when you want to listen in the
// keyboard's show/hide change.
new KeyboardUtil.OnKeyboardShowingListener() {
@Override
public void onKeyboardShowing(boolean isShowing) {
Log.d(TAG, String.format("Keyboard is %s", isShowing ? "showing" : "hiding"));
}
});
KPSwitchConflictUtil.attach(mPanelRoot, mBtnT9, mSearchEdit,
new KPSwitchConflictUtil.SwitchClickListener() {
@Override
public void onClickSwitch(boolean switchToPanel) {
if (switchToPanel) {
mSearchEdit.clearFocus();
} else {
mSearchEdit.requestFocus();
}
}
});
}
。。。。。 //重写一些方法 }
MainActivity: public class MainActivity extends Activity {
private SearchActivityView mSearchActivityView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSearchActivityView = (SearchActivityView) findViewById(R.id.search_activity_view);
mSearchActivityView.updateChangePanelState(this);
}
}
MainActivty对应的style:
`<style name="Theme.QuickSearchBox.Search" parent="@style/AppTheme">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<!-- Get rid of status bar shadow. -->
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowSoftInputMode">stateAlwaysVisible|adjustNothing</item>
<item name="android:splitMotionEvents">false</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme" parent="@android:style/Theme.DeviceDefault.Light">
</style>`
能帮我看一下吗? 感谢!
可能问题在MainActivity对应的style上,我把style加到你提供的Demo上:
<activity
android:name=".activity.ChattingResolvedActivity"
android:theme="@style/Theme.QuickSearchBox.Search"
android:label="@string/activity_chatting_resolved_title" />
也会有异常。
💯 恩。你先看看这个主题是要选择哪种适配,如果你一时半会找不出原因,你把你的主题贴给我,我抽空的时候给你看看。
主题在上面, 多谢啦~
大神, 我解决了, 是我自己选错的.... 我把KPSwitchRootLayoutHandler和KPSwitchPanelLayoutHandler写混了, 再次感谢你的这个开源方案,已用到项目中!
👍
你好,
我使用KPSwitchPanelRelativeLayout作为根布局时 应该怎么设置布局
要是加上
android:layout_above="@+id/panel_root"
android:layout_alignWithParentIfMissing="true"
输入法就不会把他顶起来了。。
我的整个布局是在自定义View上的,不是在MainActivity上。