搜索框、背景、以及Bean

 1.在Drawable下创建  显示 背景

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <stroke android:width="@dimen/dp_1" android:color="#AAAAAA" /><!--边框颜色-->
           <solid android:color="#ffffff" /><!--填充色-->
            <corners android:radius="4dp" />
        </shape>
    </item>


</layer-list>

2.按钮变色 或者切换图片.在Drawable下创建 

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@mipmap/tab_home_bottom_shouyes"/>
    <item android:state_checked="false" android:drawable="@mipmap/tab_home_bottom_shouye"/>

</selector>

3.搜索框背景

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/transparent" />
    <corners android:radius="@dimen/dp_20"/>
    <stroke
        android:width="1dip"
        android:color="#BDC7D8" />

</shape>

4.点击输入软键盘在搜索框

1.布局定义一个搜索框,用SCrowView 包着布局

<?xml version="1.0" encoding="utf-8"?>

<ScrollView android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll_scroll"
    android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="#FFFF"
    android:layout_margin="@dimen/dp_5"
    xmlns:app="http://schemas.android.com/apk/res-auto">

        <EditText
            android:id="@+id/edit_talk"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_50"
            android:hint="想说点什么"
            android:layout_weight="1"
            android:gravity="start"
            android:background="@drawable/edittext"
            />
        <TextView
            android:id="@+id/submit_talk"
            android:layout_width="match_parent"
            android:layout_height="@dimen/dp_40"
            android:layout_marginTop="@dimen/dp_10"
            android:layout_alignBaseline="@+id/edit_talk"
            android:textColor="#666666"
            android:layout_weight="5"
            android:gravity="center"

           android:textSize="@dimen/sp_12"
            android:text="提交" />
    </LinearLayout>

</ScrollView>
  edit_talk.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                    @Override
                    public void onFocusChange(View v, boolean hasFocus) {
                        controlKeyboardLayout(ll_scroll, edit_talk);
                    }
                });







 /**
     * @param root         最外层布局,需要调整的布局
     * @param scrollToView 被键盘遮挡的scrollToView,滚动root,使scrollToView在root可视区域的底部
     */
    private void controlKeyboardLayout(final View root, final View scrollToView) {
        root.getViewTreeObserver().addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        Rect rect = new Rect();
                        // 获取root在窗体的可视区域
                        root.getWindowVisibleDisplayFrame(rect);
                        // 获取root在窗体的不可视区域高度(被其他View遮挡的区域高度)
                        int rootInvisibleHeight = root.getRootView().getHeight() - rect.bottom;
                        // 若不可视区域高度大于100,则键盘显示
                        if (rootInvisibleHeight > 100) {
                            int[] location = new int[2];
                            // 获取scrollToView在窗体的坐标
                            scrollToView.getLocationInWindow(location);
                            // 计算root滚动高度,使scrollToView在可见区域
                            int srollHeight = (location[1]
                                    + scrollToView.getHeight() + dp2px(10)) - rect.bottom;
                            root.scrollTo(0, srollHeight);
                        } else {
                            // 键盘隐藏
                            root.scrollTo(0, 0);
                        }
                    }

                });
    }

5.判断Bean是否有数据

1.
 @Override
    public void success(Object data) {
        if(data instanceof NewsPLAllBean)
        {
             newsPLAllBean= (NewsPLAllBean) data;
            if(newsPLAllBean.getMessage()==null)
            {
                Toast.makeText(this, "当前无最新评论!", Toast.LENGTH_SHORT).show();
              
            }else
            {
                newsPLAllAdapter.setlist(newsPLAllBean.getResult());
            }
        }
    }


2.
  @Override
    public void success(Object data) {
        if(data instanceof NewsPLAllBean)
        {
             newsPLAllBean= (NewsPLAllBean) data;

            if(newsPLAllBean.getResult().isEmpty())
            {
                Toast.makeText(this, "当前无最新评论!", Toast.LENGTH_SHORT).show();
              
            }else
            {
                newsPLAllAdapter.setlist(newsPLAllBean.getResult());
            }
        }
    }

6.点击按钮  背景变灰色  再次点击 恢复

         //变色
WindowManager.LayoutParams attributes = this.getWindow().getAttributes();
                attributes.alpha = 0.5f;
                this.getWindow().setAttributes(attributes);
                this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);




                 WindowManager.LayoutParams attributes = this.getWindow().getAttributes();
                attributes.alpha = 0.5f;
                this.getWindow().setAttributes(attributes);

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值