Android 開發筆記___textview_聊天室效果

來源:互聯網
上載者:User

標籤:長按刪除   res   support   幹什麼   parent   static   bool   textview   mat   

 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3     android:orientation="vertical" android:layout_width="match_parent" 4     android:layout_height="match_parent"> 5  6     <TextView 7         android:layout_width="match_parent" 8         android:layout_height="wrap_content" 9         android:id="@+id/tv_control"10         android:layout_marginTop="20dp"11         android:gravity="center"12         android:text="聊天室效果,點擊添加聊天記錄,長按刪除聊天記錄"13         />14 15     <LinearLayout16         android:orientation="vertical"17         android:layout_width="match_parent"18         android:layout_height="200dp">19 20         <TextView21             android:layout_width="match_parent"22             android:layout_height="match_parent"23             android:id="@+id/tv_bbs"24             android:layout_marginTop="20dp"25             android:scrollbars="vertical"26             android:textColor="@color/text_color"27             android:textSize="17sp"/>28 29     </LinearLayout>30 31 </LinearLayout>

java

 1 package com.example.alimjan.hello_world; 2  3 import android.app.Activity; 4 import android.content.Context; 5 import android.content.DialogInterface; 6 import android.content.Intent; 7 import android.os.Bundle; 8 import android.support.annotation.Nullable; 9 import android.support.v7.app.AppCompatActivity;10 import android.text.format.DateUtils;11 import android.text.method.ScrollingMovementMethod;12 import android.view.Gravity;13 import android.view.View;14 import android.widget.TextView;15 16 /**17  * Created by alimjan on 6/30/2017.18  */19 20 public class class__2_3_1_2 extends AppCompatActivity implements DialogInterface.OnClickListener,View.OnLongClickListener, View.OnClickListener {21 22     private TextView tv_bbs,tv_control;23 24     @Override25     protected void onCreate(@Nullable Bundle savedInstanceState) {26         super.onCreate(savedInstanceState);27         setContentView(R.layout.code_2_3_1_2);28 29         tv_control = (TextView) findViewById(R.id.tv_control);30         tv_control.setOnClickListener(this);31         tv_control.setOnLongClickListener(this);32         tv_bbs = (TextView) findViewById(R.id.tv_bbs);33         tv_bbs.setOnClickListener(this);34         tv_bbs.setOnLongClickListener(this);35         tv_bbs.setGravity(Gravity.LEFT|Gravity.BOTTOM);36         tv_bbs.setLines(8);37         tv_bbs.setMaxLines(8);38         tv_bbs.setMovementMethod(new ScrollingMovementMethod());39     }40 41     private String[] mChatStr={"你吃飯了嗎honey?","今天天氣超級熱!你們那兒呢?","我中獎啦!","走不走看電影~","你在幹什嗎?"};42 43     public static void startHome(Context mContext) {44         Intent intent = new Intent(mContext, class__2_3_1_2.class);45         mContext.startActivity(intent);46     }47 48     @Override49     public void onClick(DialogInterface dialog, int which) {50 51     }52 53     @Override54     public boolean onLongClick(View v) {55         if(v.getId() == R.id.tv_control || v.getId() == R.id.tv_bbs){56             tv_bbs.setText("");57         }58         return true;59     }60 61     @Override62     public void onClick(View v) {63         if(v.getId() == R.id.tv_control || v.getId() == R.id.tv_bbs){64             int random = (int) ((Math.random()*10)%5);65             String newstr = String.format("%s\n%s%s",tv_bbs.getText().toString(), DateUtil.getCurDateStr(),mChatStr[random]);66             tv_bbs.setText(newstr);67         }68     }69 }

 

Android 開發筆記___textview_聊天室效果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.