精华内容
下载资源
问答
  • How to add a custom button

    2020-12-26 18:55:20
    <div><p>Como adicionar um botão customizado na versão 3.0 do angular-froala? <p>In the previous version it was done as follows: <p><code>declare var $: any; $.FroalaEditor.DefineIcon('assinatura...
  • shape特效定制很重要,但不经常用容易忘记,所以记录在这里方便以后需要时直接来看笔记,本人不喜欢背代码,只喜欢活学活用! 实现效果如下图中按钮的样式,有边框描边,有中间背景颜色过渡渐变,有四个...xml vers...

    shape特效定制很重要,但不经常用容易忘记,所以记录在这里方便以后需要时直接来看笔记,只因为本人不喜欢背代码,只喜欢活学活用吧!哈哈
    实现效果如下图中按钮的样式,有边框描边,有中间背景颜色过渡渐变,有四个圆角效果:

    实现很简单,只需两个步骤就行:
    第一步:在res目录下的drawable目录中创建一个btn_custom_bg_shape.xml文件,并写入如下代码:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <!--描边-->
        <stroke
            android:width="2dp"
            android:color="#ffffff"
            />
        <!--圆角度数-->
        <corners android:radius="145dp"/>
        <!--颜色填充-->
        <!--<solid android:color="#000000"/>-->
    
        <!--背景颜色渐变过渡,可以设置开始和结束的颜色渐变效果-->
        <gradient android:startColor="#541298"
            android:endColor="#541298"/>
    
    </shape>

    第二步:在想要这样效果的控件中引入该shape文件作为background属性值,布局layout和button,textview都可以这样应该。

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
    
            ...
    
             <Button
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/dp_35"
                        android:layout_marginLeft="@dimen/dp_42"
                        android:layout_marginRight="@dimen/dp_42"
                        android:textSize="@dimen/sp_17"
                        android:layout_marginTop="@dimen/dp_11"
                        android:layout_marginBottom="@dimen/dp_11"
                        android:background="@drawable/btn_custom_bg_shape"
                        android:textColor="@color/white"
                        android:text="CHECK COMPATIBILITY"/>
    
            ...
    
        </LinearLayout>

    到这里就基本实现了想要的自定义shape实现控件的圆角,描边,颜色渐变展示效果了!

    展开全文
  • noter-源码

    2021-03-19 04:48:50
    :rocket: Versão1.0 :check_mark_button: •• • • • • :magnifying_glass_tilted_right:维萨尔杰拉尔注释和注释的网络结构。 Utilizando或melhor没有后端com Node Js e Express,没有前端com React JS,...
  • <Button Name="Button" Click="Button_Click" Template="{StaticResource Start}" Width="154" Height="38" Content="start" Background="#FF26CBC1" FontFamily="Microsoft YaHei" FontSize="16" FontWeight=...
  • Localization find issue

    2020-12-26 15:10:17
    em System.Windows.Forms.Button.OnClick(EventArgs e) em System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) em System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, ...
  • :rocket: Versão1.0版本发布!!! :rocket: :check_mark_button:特征 Usabilidade /设计Telas 登录 家-本·温多(Bem Vindo) Cadastro Temperatura(Ambiente-里约) 卡达斯特罗·皮西纳斯 Lista de ...
  • AsyncTask

    2014-09-23 03:44:39
    geView控件和一个Button控件,当点击Button控件时,弹出一个ProgressDialog,然后开启一个异步任务,从网络中下载一张图片,并更新到我们的ImageView上。这里还要注意一点,如果我们要使用手机访问网络,必须还要给...
    geView控件和一个Button控件,当点击Button控件时,弹出一个ProgressDialog,然后开启一个异步任务,从网络中下载一张图片,并更新到我们的ImageView上。这里还要注意一点,如果我们要使用手机访问网络,必须还要给其授权才行,在后续的学习当中,将会详细讲解Android当中的授权的知识。我们来看看
    

    AndroidManifest.xml文件:

    复制代码
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.xiaoluo.android_asynctast"
        android:versionCode="1"
        android:versionName="1.0" >
    
        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="18" />
        
        <!-- 授权手机能够访问网络 -->
        <uses-permission android:name="android.permission.INTERNET"/>
        
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.xiaoluo.android_asynctast.MainActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>
    复制代码

    接下来我们来看看我们的Activity代码:

    复制代码
    public class MainActivity extends Activity
    {
        private Button button;
        private ImageView imageView;
        private ProgressDialog progressDialog;
        private final String IMAGE_PATH = "http://developer.android.com/images/home/kk-hero.jpg";
    //    private final String IMAGE_PATH2 = "http://ww2.sinaimg.cn/mw690/69c7e018jw1e6hd0vm3pej20fa0a674c.jpg";
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            button = (Button)findViewById(R.id.button);
            imageView = (ImageView)findViewById(R.id.imageView);
            //    弹出要给ProgressDialog
            progressDialog = new ProgressDialog(MainActivity.this);
            progressDialog.setTitle("提示信息");
            progressDialog.setMessage("正在下载中,请稍后......");
            //    设置setCancelable(false); 表示我们不能取消这个弹出框,等下载完成之后再让弹出框消失
            progressDialog.setCancelable(false);
            //    设置ProgressDialog样式为圆圈的形式
            progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            
            button.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
             // 在UI Thread当中实例化AsyncTask对象,并调用execute方法
                    new MyAsyncTask().execute(IMAGE_PATH);
                }
            });
        }
        
        /**
         * 定义一个类,让其继承AsyncTask这个类
         * Params: String类型,表示传递给异步任务的参数类型是String,通常指定的是URL路径
         * Progress: Integer类型,进度条的单位通常都是Integer类型
         * Result:byte[]类型,表示我们下载好的图片以字节数组返回
         * @author xiaoluo
         *
         */
        public class MyAsyncTask extends AsyncTask<String, Integer, byte[]>
        {
            @Override
            protected void onPreExecute()
            {
                super.onPreExecute();
                //    在onPreExecute()中我们让ProgressDialog显示出来
                progressDialog.show();
            }
            @Override
            protected byte[] doInBackground(String... params)
            {
                //    通过Apache的HttpClient来访问请求网络中的一张图片
                HttpClient httpClient = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet(params[0]);
                byte[] image = new byte[]{};
                try
                {
                    HttpResponse httpResponse = httpClient.execute(httpGet);
                    HttpEntity httpEntity = httpResponse.getEntity();
                    if(httpEntity != null && httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
                    {
                        image = EntityUtils.toByteArray(httpEntity);
                    }
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
                finally
                {
                    httpClient.getConnectionManager().shutdown();
                }
                return image;
            }
            @Override
            protected void onProgressUpdate(Integer... values)
            {
                super.onProgressUpdate(values);
            }
            @Override
            protected void onPostExecute(byte[] result)
            {
                super.onPostExecute(result);
                //    将doInBackground方法返回的byte[]解码成要给Bitmap
                Bitmap bitmap = BitmapFactory.decodeByteArray(result, 0, result.length);
                //    更新我们的ImageView控件
                imageView.setImageBitmap(bitmap);
                //    使ProgressDialog框消失
                progressDialog.dismiss();
            }
        }
        
        @Override
        public boolean onCreateOptionsMenu(Menu menu)
        {
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
    }
    复制代码

    我们来看看效果图:

     

     

    ②带有进度条更新的下载一张网络图片

    下面这个代码示例,将会在下载图片的时候,显示进度条的更新,配置文件都不变,我们来看看Activity代码:

    复制代码
    public class MainActivity extends Activity
    {
        private Button button;
        private ImageView imageView;
        private ProgressDialog progressDialog;
        private final String IMAGE_PATH = "http://developer.android.com/images/home/kk-hero.jpg";
    //    private final String IMAGE_PATH2 = "http://ww2.sinaimg.cn/mw690/69c7e018jw1e6hd0vm3pej20fa0a674c.jpg";
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            button = (Button)findViewById(R.id.button);
            imageView = (ImageView)findViewById(R.id.imageView);
            //    弹出要给ProgressDialog
            progressDialog = new ProgressDialog(MainActivity.this);
            progressDialog.setTitle("提示信息");
            progressDialog.setMessage("正在下载中,请稍后......");
            //    设置setCancelable(false); 表示我们不能取消这个弹出框,等下载完成之后再让弹出框消失
            progressDialog.setCancelable(false);
            //    设置ProgressDialog样式为水平的样式
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            
            button.setOnClickListener(new View.OnClickListener()
            {
                @Override
                public void onClick(View v)
                {
                    new MyAsyncTask().execute(IMAGE_PATH);
                }
            });
        }
        
        /**
         * 定义一个类,让其继承AsyncTask这个类
         * Params: String类型,表示传递给异步任务的参数类型是String,通常指定的是URL路径
         * Progress: Integer类型,进度条的单位通常都是Integer类型
         * Result:byte[]类型,表示我们下载好的图片以字节数组返回
         * @author xiaoluo
         *
         */
        public class MyAsyncTask extends AsyncTask<String, Integer, byte[]>
        {
            @Override
            protected void onPreExecute()
            {
                super.onPreExecute();
                //    在onPreExecute()中我们让ProgressDialog显示出来
                progressDialog.show();
            }
            @Override
            protected byte[] doInBackground(String... params)
            {
                //    通过Apache的HttpClient来访问请求网络中的一张图片
                HttpClient httpClient = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet(params[0]);
                byte[] image = new byte[]{};
                try
                {
                    HttpResponse httpResponse = httpClient.execute(httpGet);
                    HttpEntity httpEntity = httpResponse.getEntity();
                    InputStream inputStream = null;
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    if(httpEntity != null && httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
                    {
                        //    得到文件的总长度
                        long file_length = httpEntity.getContentLength();
                        //    每次读取后累加的长度
                        long total_length = 0;
                        int length = 0;
                        //    每次读取1024个字节
                        byte[] data = new byte[1024];
                        inputStream = httpEntity.getContent();
                        while(-1 != (length = inputStream.read(data)))
                        {
                            //    每读一次,就将total_length累加起来
                            total_length += length;
                            //    边读边写到ByteArrayOutputStream当中
                            byteArrayOutputStream.write(data, 0, length);
                            //    得到当前图片下载的进度
                            int progress = ((int)(total_length/(float)file_length) * 100);
                            //    时刻将当前进度更新给onProgressUpdate方法
                            publishProgress(progress);
                        }
                    }
                    image = byteArrayOutputStream.toByteArray();
                    inputStream.close();
                    byteArrayOutputStream.close();
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
                finally
                {
                    httpClient.getConnectionManager().shutdown();
                }
                return image;
            }
            @Override
            protected void onProgressUpdate(Integer... values)
            {
                super.onProgressUpdate(values);
                //    更新ProgressDialog的进度条
                progressDialog.setProgress(values[0]);
            }
            @Override
            protected void onPostExecute(byte[] result)
            {
                super.onPostExecute(result);
                //    将doInBackground方法返回的byte[]解码成要给Bitmap
                Bitmap bitmap = BitmapFactory.decodeByteArray(result, 0, result.length);
                //    更新我们的ImageView控件
                imageView.setImageBitmap(bitmap);
                //    使ProgressDialog框消失
                progressDialog.dismiss();
            }
        }
        
        @Override
        public boolean onCreateOptionsMenu(Menu menu)
        {
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
    }
    复制代码

    我们来看看效果图:

     

    这样我们就能够通过AsyncTask来实现从网络中下载一张图片,然后将其更新到UI控件中,并时时刻刻的更新当前的进度这个功能了。

    六、AsyncTask的重要知识点

    在上面两节已经详细讲解了AsyncTask的工作原理了,这里我们还要补充一下AsyncTask的一些其他知识点:

    1.Cancelling a Task

    我们可以在任何时刻来取消我们的异步任务的执行,通过调用 cancel(boolean)方法,调用完这个方法后系统会随后调用 isCancelled() 方法并且返回true。如果调用了这个方法,那么在 doInBackgroud() 方法执行完之后,就不会调用 onPostExecute() 方法了,取而代之的是调用 onCancelled() 方法。为了确保Task已经被取消了,我们需要经常调用 isCancelled() 方法来判断,如果有必要的话。

    2.在使用AsyncTask做异步任务的时候必须要遵循的原则:

    • AsyncTask类必须在UI Thread当中加载,在Android Jelly_Bean版本后这些都是自动完成的
    • AsyncTask的对象必须在UI Thread当中实例化
    • execute方法必须在UI Thread当中调用
    • 不要手动的去调用AsyncTask的onPreExecute, doInBackground, publishProgress, onProgressUpdate, onPostExecute方法,这些都是由Android系统自动调用的
    • AsyncTask任务只能被执行一次

     

    到此,有关AsyncTask的总结就到此为止了,本篇随笔主要讲解了Android中的多线程知识,并且详细地讲解了 AsyncTask 异步任务的概念和实现机制,并通过实例来了解 AsyncTask 的执行过程,最后还补充了 AsyncTask 的一些重要知识点,包括如何取消一个 AsyncTask 以及,我们在使用 AsyncTask 时所必须遵循的规则。

    展开全文
  • 因为表情包实现比较麻烦,现在还在做,做完了发,还有就是对话框和微信不一样是因为没有合适的对话框的png图片用来做.9的图片. 依赖 implementation 'androidx.recyclerview:recyclerview:1.0.0' ...xml vers...

    因为表情包实现比较麻烦,现在还在做,做完了发,还有就是对话框和微信不一样是因为没有合适的对话框的png图片用来做.9的图片.

    依赖

    implementation 'androidx.recyclerview:recyclerview:1.0.0'

    在drawable里新建几个drawable resource file

    buttonbackground

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient
            android:angle="45"
            android:startColor="@color/colorGreen"
            android:endColor="@color/colorGreen"/>
        <size
            android:width="45dp"
            android:height="25dp"
            />
        <corners
            android:radius="5dp"/>
    
    </shape>

    dialog_left

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid
            android:color="@color/colorGreen"/>
        <corners
            android:bottomLeftRadius="85dp"
            android:topLeftRadius="85dp"
            android:bottomRightRadius="10dp"
            android:topRightRadius="10dp"
            />
    
    
    </shape>

    dialog_right

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid
            android:color="@color/colorWhite"/>
        <corners
            android:bottomRightRadius="85dp"
            android:topRightRadius="85dp"
            android:topLeftRadius="10dp"
            android:bottomLeftRadius="10dp"
            />
    
    
    </shape>

    inputbackground

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <corners android:radius="10dp" />
        <solid android:color="@color/colorWhite" />
    </shape>

     用到的颜色

    <color name="colorAccent">#12de20</color>
        <color name="colorGreen">#12de20</color>
        <color name="colorGray">#bfbfbf</color>
        <color name="colorLightGray">#ECE9E9</color>
        <color name="colorLighterGray">#F3F3F3</color>

     

    界面

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/parent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:orientation="vertical"
        tools:context=".activity.ItemDetail">
    
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/msg_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorLightGray"
            android:fitsSystemWindows="true"
            app:navigationIcon="@drawable/ic_arrow_back_black_24dp"
            app:title="@string/app_name" />
    
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/msg_list"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@color/colorLightGray"
            android:fitsSystemWindows="true" />
    
        <LinearLayout
            android:id="@+id/linear"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="@color/colorLighterGray"
            android:fitsSystemWindows="true"
            android:orientation="vertical">
    
            <View
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:background="@color/colorGray" />
    
            <LinearLayout
                android:layout_width="match_parent"
                android:padding="5dp"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:layout_gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/inputbackground"
                    android:layout_weight="1"
                    >
    
                <EditText
                    android:id="@+id/msg_say"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginStart="5dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginEnd="5dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginBottom="5dp"
                    android:layout_weight="1"
                    android:background="@color/colorWhite"
                    android:hint="输入你想说的话" />
    
    
                </LinearLayout>
                <Button
                    android:id="@+id/msg_emoji"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginLeft="3dp"
                    android:layout_marginBottom="5dp"
                    android:background="@drawable/ic_mood_black_24dp" />
    
                <Button
                    android:id="@+id/msg_send"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginBottom="5dp"
                    android:background="@drawable/ic_add_24dp" />
            </LinearLayout>
    
        </LinearLayout>
    
    </LinearLayout>

    Msg类

    package com.example.wechat.bean;
    
    public class Msg {
        public static final int type_received = 0;
        public static final int type_sent = 1;
        private String content;
        private int type;
        private int headerid;
    
        public Msg(String content, int type) {
            this.content = content;
            this.type = type;
        }
    
        public static int getType_sent() {
            return type_sent;
        }
    
        public String getContent() {
            return content;
        }
    
        public void setContent(String content) {
            this.content = content;
        }
    
        public int getType() {
            return type;
        }
    
        public void setType(int type) {
            this.type = type;
        }
    
        public int getHeaderid() {
            return headerid;
        }
    
        public void setHeaderid(int headerid) {
            this.headerid = headerid;
        }
    
        public static int getType_received() {
            return type_received;
        }
    }
    

    msg_item,这里根布局要用相对布局,线性布局出bug

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="10dp">
    
        <LinearLayout
            android:id="@+id/left_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_gravity="left"
            android:background="@drawable/dialog_left"
            android:orientation="horizontal"
            tools:ignore="RtlHardcoded">
    
            <TextView
                android:id="@+id/left_msg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="10dp"
                android:text="123"
                android:textColor="#fff"
                android:textIsSelectable="true"
                android:textSize="20sp" />
    
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/right_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_gravity="right"
            android:background="@drawable/dialog_right"
            android:orientation="horizontal"
            tools:ignore="RtlHardcoded">
    
            <TextView
                android:id="@+id/right_msg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_margin="10dp"
                android:text="123"
                android:textColor="#000"
                android:textIsSelectable="true"
                android:textSize="20sp" />
    
    
        </LinearLayout>
    </RelativeLayout>

    MsgAdapter

    package com.example.wechat.adapter;
    
    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.LinearLayout;
    import android.widget.TextView;
    
    import com.example.wechat.R;
    import com.example.wechat.bean.Msg;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import androidx.annotation.NonNull;
    import androidx.recyclerview.widget.RecyclerView;
    
    public class MsgAdapter extends RecyclerView.Adapter<MsgAdapter.ViewHolder> {
        List<Msg> msgs = new ArrayList<>();
        Context context;
        LayoutInflater inflater;
    
        public MsgAdapter(List<Msg> msgs, Context context) {
            this.msgs = msgs;
            this.context = context;
            inflater = LayoutInflater.from(context);
        }
    
        @NonNull
        @Override
        public MsgAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view = inflater.inflate(R.layout.msg_item, null);
            ViewHolder viewHolder = new ViewHolder(view);
            return viewHolder;
        }
    
        @Override
        public void onBindViewHolder(@NonNull MsgAdapter.ViewHolder holder, int position) {
            Msg msg = msgs.get(position);
            if (msg.getType() == Msg.type_received) {
                holder.left_layout.setVisibility(View.VISIBLE);
                holder.right_layout.setVisibility(View.GONE);
                holder.left_msg.setText(msg.getContent());
            } else if (msg.getType() == Msg.type_sent) {
                holder.right_layout.setVisibility(View.VISIBLE);
                holder.left_layout.setVisibility(View.GONE);
                holder.right_msg.setText(msg.getContent());
    
            }
        }
    
        @Override
        public int getItemCount() {
            return msgs.size();
        }
    
        public class ViewHolder extends RecyclerView.ViewHolder {
            TextView left_msg;
            TextView right_msg;
            LinearLayout left_layout;
            LinearLayout right_layout;
    
            public ViewHolder(@NonNull View itemView) {
                super(itemView);
                left_msg = itemView.findViewById(R.id.left_msg);
                right_msg = itemView.findViewById(R.id.right_msg);
                left_layout = itemView.findViewById(R.id.left_layout);
                right_layout = itemView.findViewById(R.id.right_layout);
            }
        }
    }
    

    ItemDetail,这里加了如果输入框里有字就显示发送,否则就显示加号,最后还加了一个手动触摸返回的功能

    package com.example.wechat.activity;
    
    import androidx.appcompat.app.AppCompatActivity;
    import androidx.appcompat.widget.Toolbar;
    import androidx.recyclerview.widget.LinearLayoutManager;
    import androidx.recyclerview.widget.RecyclerView;
    
    import android.annotation.SuppressLint;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Build;
    import android.os.Bundle;
    import android.text.Editable;
    import android.text.TextWatcher;
    import android.util.Log;
    import android.view.MotionEvent;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.LinearLayout;
    import android.widget.Toast;
    
    import com.example.wechat.R;
    import com.example.wechat.adapter.MsgAdapter;
    import com.example.wechat.bean.Msg;
    import com.example.wechat.bean.User;
    import com.example.wechat.util.StatusBarUtils;
    import com.example.wechat.util.WithSoftUp;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class ItemDetail extends AppCompatActivity {
        List<Msg> list = new ArrayList<>();
        RecyclerView recyclerView;
        Toolbar toolbar;
        MsgAdapter msgAdapter;
        Context context = ItemDetail.this;
        EditText msg_say;
        Button emoji;
        Button send;
        LinearLayout linearLayout;
        int lastx = 0;
        int lasty = 0;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_item_detail);
            recyclerView = findViewById(R.id.msg_list);
            toolbar = findViewById(R.id.msg_toolbar);
            msg_say = findViewById(R.id.msg_say);
            emoji = findViewById(R.id.msg_emoji);
            send = findViewById(R.id.msg_send);
            linearLayout = findViewById(R.id.linear);
            initData();
            initView();
            initStatusBar();
        }
    
        private void initStatusBar() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
                StatusBarUtils.setStatusBarColor(ItemDetail.this, R.color.colorLightGray);
            }
        }
    
        private void initData() {
            User user = (User) getIntent().getSerializableExtra("user_data");
            toolbar.setTitle(user.getName());
    
            Msg msg = new Msg("hello,hello,hello,hello,hello,hello", Msg.type_received);
            list.add(msg);
            Msg msg1 = new Msg("hello", Msg.type_sent);
            list.add(msg1);
    
    
        }
    
        private void initView() {
            LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
            recyclerView.setLayoutManager(linearLayoutManager);
            msgAdapter = new MsgAdapter(list, context);
            recyclerView.setAdapter(msgAdapter);
            toolbar.setNavigationOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
            send.getLayoutParams().width = emoji.getLayoutParams().width;
            msg_say.addTextChangedListener(textWatcher);
            WithSoftUp.addLayoutListener(findViewById(R.id.parent), linearLayout);
            send.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (msg_say.getEditableText().length() >= 1) {
                        String content = msg_say.getText().toString();
                        if (!"".equals(content)) {
                            Msg msg = new Msg(content, Msg.type_sent);
                            list.add(msg);
                            Msg msg1 = new Msg(content, Msg.type_received);
                            list.add(msg1);
                            msgAdapter.notifyItemInserted(list.size() - 1);
                            recyclerView.scrollToPosition(list.size() - 1);
                            msg_say.setText("");
    
                        }
                    } else {
                        Toast.makeText(context, "点击add", Toast.LENGTH_SHORT).show();
                    }
                }
            });
        }
    
        TextWatcher textWatcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
            }
    
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
    
            }
    
            @SuppressLint("ResourceAsColor")
            @Override
            public void afterTextChanged(Editable s) {
                if (msg_say.getEditableText().length() >= 1) {
                    send.setBackgroundResource(R.drawable.buttonbackground);
                    send.setText("发送");
                    send.getLayoutParams().height = emoji.getLayoutParams().height;
                    send.getLayoutParams().width = emoji.getLayoutParams().width + 30;
                    send.setTextColor(context.getResources().getColor(R.color.colorWhite));
                } else {
                    send.setBackgroundResource(R.drawable.ic_add_24dp);
                    send.getLayoutParams().height = emoji.getLayoutParams().height;
                    send.getLayoutParams().width = emoji.getLayoutParams().width;
                    send.setText("");
                }
            }
        };
    
        @Override
        public boolean dispatchTouchEvent(MotionEvent event) {
            int x = (int) event.getX();
            int y = (int) event.getY();
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    lastx = x;
                    lasty = y;
                    break;
                case MotionEvent.ACTION_UP:
                    int curx = x;
                    int cury = y;
    
                    if (curx-lastx>300&&Math.abs(cury-lasty)<200)
                        finish();
                    break;
            }
            return super.dispatchTouchEvent(event);
        }
    
    }
    

     

    展开全文
  • ListView与RecyclerView在在app应用非常广泛,相对于其他的view(button textview)来说比较复杂,接下来我将讲一下创建的流程以及两者的不同。 代码来自《第一行代码》 秋天到了,果园大丰收了,现在着急的事情...

    ListView与RecyclerView在在app应用非常广泛,相对于其他的view(button textview)来说比较复杂,接下来我将讲一下创建的流程以及两者的不同。


    代码来自《第一行代码》

    秋天到了,果园大丰收了,现在着急的事情,就是把水果收集好放进仓库里。

    ListView

    1. 首先肯定要先把仓库准备好,腾一块地方出来,在布局中添加ListView。

       <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:orientation="vertical"
           android:layout_width="match_parent"
           android:layout_height="match_parent">
      
           <ListView
               android:id="@+id/list_view"
               android:layout_width="match_parent"
               android:layout_height="match_parent" >
           </ListView>
      
       </LinearLayout>
    2. 把装水果的框子准备好,创建fruit_item布局。

       <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:orientation="horizontal"
           android:layout_width="match_parent"
           android:layout_height="match_parent">
      
           <ImageView
               android:id="@+id/fruit_image"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content" />
      
           <TextView
               android:id="@+id/fruit_name"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_gravity="center_vertical"
               android:layout_marginLeft="10dp" />
      
       </LinearLayout>
    3. 主角登场啦,咱们的搬运工,创建类FruitAdapter。

    他需要干什么呢?

    先贴出源码,下面解释

        package com.example.listviewtest;
        
        import android.content.Context;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.ArrayAdapter;
        import android.widget.ImageView;
        import android.widget.TextView;
        
        import java.util.List;
        
        public class FruitAdapter extends ArrayAdapter<Fruit> {
        
            private int resourceId;
        
            public FruitAdapter(Context context, int textViewResourceId,
                                List<Fruit> objects) {
                super(context, textViewResourceId, objects);
                resourceId = textViewResourceId;
            }
        
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                Fruit fruit = getItem(position); // 获取当前项的Fruit实例
                View view;
                ViewHolder viewHolder;
                if (convertView == null) {
                    view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
                    viewHolder = new ViewHolder();
                    viewHolder.fruitImage = (ImageView) view.findViewById (R.id.fruit_image);
                    viewHolder.fruitName = (TextView) view.findViewById (R.id.fruit_name);
                    view.setTag(viewHolder); // 将ViewHolder存储在View中
                } else {
                    view = convertView;
                    viewHolder = (ViewHolder) view.getTag(); // 重新获取ViewHolder
                }
                viewHolder.fruitImage.setImageResource(fruit.getImageId());
                viewHolder.fruitName.setText(fruit.getName());
                return view;
            }
        
            class ViewHolder {
        
                ImageView fruitImage;
        
                TextView fruitName;
        
            }
        
        }

    搬运工的工作就是,返回一个装满水果的框框

    • 拿到一个水果
    • 找到一个框框
    • 把水果放到框框里
    • 把框框返回(结局自然回到里仓库)
      1. 拿到一个水果

         Fruit fruit = getItem(position);
      2. 找到一个框框

         View view;
         view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
         ImageView fruitImage = (ImageView) view.findViewById(R.id.fruit_image)
         TextView fruitName = (TextView) view.findViewById(R.id.fruit_name)
      3. 把水果放到框框里

         viewHolder.fruitImage.setImageResource(fruit.getImageId());
         viewHolder.fruitName.setText(fruit.getName());

        源码里面有两布优化,自己想想哦。

      4.把框框返回

            return view;

    RecylerView

    还是老步骤,首先准备好仓库,在准备好框框

    1. 准备好仓库,腾一块地方出来

       <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:layout_width="match_parent"
           android:layout_height="match_parent">
      
           <android.support.v7.widget.RecyclerView
               android:id="@+id/recycler_view"
               android:layout_width="match_parent"
               android:layout_height="match_parent" />
      
       </LinearLayout>
    2. 准备好框框,和上面一样

       <?xml version="1.0" encoding="utf-8"?>
       <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
           android:orientation="vertical"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:layout_margin="5dp" >
      
           <ImageView
               android:id="@+id/fruit_image"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_gravity="center_horizontal" />
      
           <TextView
               android:id="@+id/fruit_name"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_gravity="left"
               android:layout_marginTop="10dp" />
      
       </LinearLayout>
    3. 请出我们更加聪明的搬运工了

      先贴出源码,下面解释

      package com.example.recyclerviewtest;

      import android.support.v7.widget.RecyclerView;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.ImageView;
      import android.widget.TextView;
      import android.widget.Toast;

      import java.util.List;

      public class FruitAdapter extends RecyclerView.Adapter<FruitAdapter.ViewHolder>{

       private List<Fruit> mFruitList;
      
       static class ViewHolder extends RecyclerView.ViewHolder {
           View fruitView;
           ImageView fruitImage;
           TextView fruitName;
      
           public ViewHolder(View view) {
               super(view);
               fruitView = view;
               fruitImage = (ImageView) view.findViewById(R.id.fruit_image);
               fruitName = (TextView) view.findViewById(R.id.fruit_name);
           }
       }
      
       public FruitAdapter(List<Fruit> fruitList) {
           mFruitList = fruitList;
       }
      
       @Override
       public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
           View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fruit_item, parent, false);
           final ViewHolder holder = new ViewHolder(view);
           holder.fruitView.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                   int position = holder.getAdapterPosition();
                   Fruit fruit = mFruitList.get(position);
                   Toast.makeText(v.getContext(), "you clicked view " + fruit.getName(), Toast.LENGTH_SHORT).show();
               }
           });
           holder.fruitImage.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                   int position = holder.getAdapterPosition();
                   Fruit fruit = mFruitList.get(position);
                   Toast.makeText(v.getContext(), "you clicked image " + fruit.getName(), Toast.LENGTH_SHORT).show();
               }
           });
           return holder;
       }
      
       @Override
       public void onBindViewHolder(ViewHolder holder, int position) {
           Fruit fruit = mFruitList.get(position);
           holder.fruitImage.setImageResource(fruit.getImageId());
           holder.fruitName.setText(fruit.getName());
       }
      
       @Override
       public int getItemCount() {
           return mFruitList.size();
       }

      }

    多了好多诶,其实,咱们聪明的搬运工制造了更多的工具,真是方便了好多。
    现在搬运工只需要干两件事情了

    • 找到一个水果
    • 把水果放到框子里

        public void onBindViewHolder(ViewHolder holder, int position) {
            Fruit fruit = mFruitList.get(position);
            holder.fruitImage.setImageResource(fruit.getImageId());
            holder.fruitName.setText(fruit.getName());
        }

      没错,只需要两部,其他的事情都靠聪明的搬运工制造出来的自动小车,送回到仓库了,是不是很酷。

    • 现在创造出我们的工具

        static class ViewHolder extends RecyclerView.ViewHolder {
            View fruitView;
            ImageView fruitImage;
            TextView fruitName;
      
            public ViewHolder(View view) {
                super(view);
                fruitView = view;
                fruitImage = (ImageView) view.findViewById(R.id.fruit_image);
                fruitName = (TextView) view.findViewById(R.id.fruit_name);
            }
        }

      这个工具记得他应该去仓库中腾出来的位置

    • 再看看工具是怎么运作的

        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fruit_item, parent, false);
            ViewHolder holder = new ViewHolder(view);
            return holder;
        }

      首先他会和仓库联系一下,然后就会自动运回仓库啦。

    转载于:https://www.cnblogs.com/XD00/p/9961420.html

    展开全文
  • <p>IceStorm vers: Yosys 0.5+460 (git sha1 45af4a4, clang 3.4-1ubuntu3 -fPIC -Os) arachne-pnr 0.1+136+0 (git sha1 1a4fdf9, g++ 4.8.4-2ubuntu1~14.04.1 -O2)</p><p>该提问来源于开源项目...
  • Add miniteresa.sh script

    2020-12-28 11:13:54
    <div><p>Primeira versão, por enquanto ainda um protótipo. <p>This change is <a href="https://reviewable.io/reviews/luizalabs/tapi/105"><img src=...
  • 简易短信发送器

    2017-11-03 11:26:00
     由于我这里写的是一个简易的,,短信发送,所以只是一个LinearLayout下放了两个EditText用来存号码和内容,还有一个Button发送按钮,如果想要更华丽的布局,有兴趣的大家可以再去添加奥。 1 <?xml vers.....
  • Android Studio 创建自定义控件

    千次阅读 2019-05-09 17:31:34
    下面来自定义一个控件,iPhone的标题栏,创建一个标题栏并不是什么难事,加入两个button一个TextView就行了,可是在我们的应用中,有很多页面都是需要这样的标题栏,我们不可能每个活动都写一遍布局,这个时候我们就...
  • Focus store vers. 4.0.2 Klar+GeckoView 4.1 <p>Devices: Samsung Galaxy S8 (Android 7.0) HTC Desire 820 (Android 6.0.1) <p>STR: 1. Open one of the following apps: Amazon News republic Google News 2....
  • Error memory DSI v4.415

    2020-12-05 15:11:42
    <div><p>Acabei de atualizar o nintendont para versão V4.415 , de três vezes que tentei, duas vezes quando entro nas opções e clico o botão Home do remote para sair para o HomeBrew channel, da o ...
  • vers. 1.2.0 <p><strong>Issue description</strong>: <p>About every other time I open the preview window Synfig stops and crashes. This occurs shortly after pressing the "Preview" button on the ...
  • 在控制面板的直接设置  FLEX里style面板里都可以设置相关组件字体的样式,例如button、lable、checkbox等字体,直接在上面设置就行了。它自动生成的代码如 下:   <?xml vers
  • button my terminal shows me the following : arnaud-portable ~/04024r3 $ ./startlnp /tmp/_MEIivTsik/xdg-terminal: 364: [: x/home/arnaud/04024r3/df_linux/dfhack: unexpected operator /tmp/_...
  • Major release vers</code></p> <p>In Arduino/libraries/MySensors/core/Version.h, in MYSENSORS_LIBRARY_VERSION_MINOR is this truncated message. This makes mysensors in the home assistant not work. <p>...
  • 22:36:32:227 [INFO] - Found file containing button maps. Parsing data... 22:36:32:306 [INFO] - Button maps loaded. 22:36:32:346 dlg action: Read binding table 22:36:32:359 found node plugin: libde_...
  • 13:14:41:572 [INFO] - Found file containing button maps. Parsing data... 13:14:41:576 [INFO] - Button maps loaded. 13:14:41:577 dlg action: Read binding table 13:14:41:577 found node plugin: libde_...
  • <div><p>…vers. The checkboxes in the manage view are now useful outside of the chooser. Clicking "Edit" on an item in the trash was just giving you an error - now you get a "Rescue" ...
  • Focus store vers. 4.0.2 Klar+GeckoView 4.1 <p>Devices: Samsung Galaxy S8 (Android 7.0) HTC Desire 820 (Android 6.0.1) <p>STR: 1. Open the News Republic app. 2. Open an article. 3. Tap the share ...
  • taranis firmware was VERS: 2.0.13 , nightly builds from the last two weeks. i currently update firmware mostly daily because the last bugs and fixes. </p><p>该提问来源于开源项目:opentx/opentx...
  • Alias redirigé vers l'adresse : <button href="#modifalias" role="link" data-toggle="modal" class="btn btn-primary"><i class="icon-plus icon-white"></i></button> </H4>...
  • Retour vers le formulaire</button> </div> </div> </div> </div>"); // Send the email $to = "myemail"; $subject = "Contact Form: $name"; $message = "$message"; $...
  • 1.7.4.x

    2021-01-12 19:52:46
    ajout au panier (avant que la page soit complètement chargée et que le javascript de la génération du pop-up panier soit chargé) nous sommes redirigé vers le panier dans lequel notre produit n&#...
  • EEPROM ALERT, EEprom Data v217, button for continu" - EEprom conversion - The color top screen display a voltage at 0V for 1sec and then the good voltage - The bottom screen back to the start menu...

空空如也

空空如也

1 2 3
收藏数 54
精华内容 21
关键字:

buttonvers