当前位置: 编程技术>移动开发
本页文章导读:
▪[课程]隐藏ActionBar中的MenuItem [教程]隐藏ActionBar中的MenuItem
有时候我们需要在不同的时候改变ActionBar中MenuItem的项数,或者隐藏某些MenuItem,百度上找了很久没什好资料,还是Google了一下,StackOverFlow上有大神解决了。
先.........
▪ Andoir 判断软键盘是不是弹出 Andoir 判断软键盘是否弹出
前言
欢迎大家我分享和推荐好用的代码段~~
声明
欢迎转载,但请保留文章原始出处:
CSDN:http://www.csdn.net
雨.........
▪ onMeasure跟childview.layout onMeasure和childview.layoutpublic class CustomViewGroup extends ViewGroup{
public CustomViewGroup(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onMeasure(int widthMeasureSpec, int hei.........
[1][课程]隐藏ActionBar中的MenuItem
来源: 互联网 发布时间: 2014-02-18
[教程]隐藏ActionBar中的MenuItem
有时候我们需要在不同的时候改变ActionBar中MenuItem的项数,或者隐藏某些MenuItem,百度上找了很久没什好资料,还是Google了一下,StackOverFlow上有大神解决了。
先看看 StackOverFlow 上的问题:
How do I hide a menu item in the actionbar? 我来总结一下:
(1)在Activity的onCreateOptionMenu()方法中获取每一个MenuItem,然后再满足某一条件下调用setVisible()方法隐藏该MenuItem。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.action_main, menu);
MenuItem actionSettings = menu.findItem(R.id.action_settings);
if(...满足某一条件...){
actionSettings.setVisible(true);
else{
actionSettings.setVisible(false);
}
return true;
}
(2)调用Activity的invalidateOptionsMenu()方法,Activity就会重新调用onCreateOptionMenu()方法重新生成ActionBar。不过 invalidateOptionsMenu() 这个方法只有API11以上才能用,但不用担心,Google在V4包的FragmentActivity中也提供了一个supportInvalidateOptionsMenu()方法。
[2] Andoir 判断软键盘是不是弹出
来源: 互联网 发布时间: 2014-02-18
Andoir 判断软键盘是否弹出
前言
欢迎大家我分享和推荐好用的代码段~~
声明
欢迎转载,但请保留文章原始出处:
CSDN:http://www.csdn.net
雨季o莫忧离:http://blog.csdn.net/luckkof
正文
private boolean mHasInit = false;
private boolean mHasKeyboard = false;
private int mHeight;
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
super.onLayout(changed, l, t, r, b);
if(!mHasInit) {
mHasInit = true;
mHeight = b;
System.out.println("mHeight= "+b);
} else {
mHeight = mHeight < b ? b : mHeight;
}
if(mHasInit && mHeight > b) { //mHeight代表键盘的真实高度 ,b代表在窗口中的高度 mHeight>b
mHasKeyboard = true;
Xlog.e(TAG, "bottomBar---------------->出来了");
}
if(mHasInit && mHasKeyboard && mHeight == b) { // mHeight = b
mHasKeyboard = false;
cancelBottomBarAnimation();
this.setVisibility(View.VISIBLE);
mShowing = false;
Xlog.e(TAG, "bottomBar---------------->隐藏了");
}
}
[3] onMeasure跟childview.layout
来源: 互联网 发布时间: 2014-02-18
onMeasure和childview.layout
public class CustomViewGroup extends ViewGroup{
public CustomViewGroup(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
/**
* 依据specMode的值,如果是AT_MOST,specSize 代表的是最大可获得的空间;如果是EXACTLY,specSize 代表的是精确的尺寸;如果是UNSPECIFIED,对于控件尺寸来说,没有任何参考意义。
*/
if (widthMode != MeasureSpec.EXACTLY || heightMode != MeasureSpec.EXACTLY)
{
throw new IllegalStateException("ApplicationsStackLayout can only be used with "
+ "measure spec mode=EXACTLY");
}
measureChildren(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(widthSize, heightSize);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// TODO Auto-generated method stub
int mTotalHeight = 0;
// 遍历所有子视图
int childCount = getChildCount();
for (int i = 0; i < childCount; i++) {
View childView = getChildAt(i);
// 获取在onMeasure中计算的视图尺寸
int measureHeight = childView.getMeasuredHeight();
int measuredWidth = childView.getMeasuredWidth();
if(i==1){
childView.layout(50, mTotalHeight, measuredWidth+50, mTotalHeight + measureHeight);
}else
childView.layout(l, mTotalHeight, measuredWidth, mTotalHeight + measureHeight);
mTotalHeight += measureHeight;
}
}
}
使用自定义的ViewGroup
<CustomViewGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff">
<TextView android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="fasdjflsadjlf"
android:background="#555555"/>
<TextView android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="fasdjflsadjlf"
android:background="#999999"/>
</CustomViewGroup>
最新技术文章: