Android端的微博项目

2024-09-01 14:08
文章标签 android 微博 项目 端的

本文主要是介绍Android端的微博项目,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

登录界面如下:

 

每个控件都要实现功能。例如:申请账号按钮被点击后转到一个新的Activity,进行帐号申请的工作。

登录按钮被点击后转到微博界面(一个新的Activity),在TextView里显示以前发布的微博内容和时间(可以设置多个TextView),并有按钮“发布新微博”和“返回”。

发布新微博按钮被点击后转到一个新的Activity,该页面有一个TextView、一个EditText,一个“提交”按钮。TextView提示EditText剩余的字符数,超出限制后进行提醒,EditText的最大字符数是300。点击提交按钮后转到微博界面.

主界面:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button bt1 = (Button) findViewById(R.id.button1);Button bt2 = (Button) findViewById(R.id.button2);bt1.setOnClickListener(listener);bt2.setOnClickListener(listener2);}private OnClickListener listener=new OnClickListener(){public void onClick(View arg0) {// TODO Auto-generated method stubIntent intent=new Intent();intent.setClass(MainActivity.this, LoginActivity.class);startActivity(intent);}};private OnClickListener listener2=new OnClickListener(){public void onClick(View arg0) {// TODO Auto-generated method stubIntent intent=new Intent();intent.setClass(MainActivity.this, RegisterActivity.class);startActivity(intent);}};
}
Main.xml:
<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="match_parent"android:background="@drawable/wbz"tools:context=".MainActivity" ><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="欢迎进入微博主页"android:textSize="30sp" android:layout_marginLeft="40dp"/><ImageViewandroid:id="@+id/img"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:src="@drawable/weibo" /><EditTextandroid:id="@+id/editText1"android:singleLine="true"android:layout_width="280dp"android:layout_height="wrap_content"android:layout_below="@+id/textView1"android:layout_marginLeft="25dp"android:layout_marginTop="153dp"android:hint="请输入账号" /><EditTextandroid:id="@+id/editText2"android:singleLine="true"android:layout_width="280dp" android:layout_height="wrap_content"android:layout_below="@+id/editText1"android:layout_marginLeft="25dp"android:text="请输入密码"android:inputType="textPassword" /><Buttonandroid:id="@+id/button1"android:layout_width="120dp"android:layout_height="wrap_content"android:layout_below="@+id/editText2"android:layout_marginLeft="20dp"android:layout_marginTop="30dp"android:text="申请账号" /><Buttonandroid:id="@+id/button2"android:layout_width="120dp"android:layout_height="wrap_content"android:layout_alignBottom="@+id/button1"android:layout_marginLeft="180dp"android:text="登录" />
</RelativeLayout>

注册:

LoginActivity
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class LoginActivity  extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.login);Button bt = (Button) findViewById(R.id.btLogin);bt.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubIntent intent = new Intent();intent.setClass(LoginActivity.this, MainActivity.class);startActivity(intent);}});}
}
Login.xml:
<?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" ><TextViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:text="注册信息"android:textSize="30sp"android:layout_marginLeft="80dp" /><LinearLayoutandroid:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"><TextView android:id="@+id/tv1"android:layout_width="50dp"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:text="昵称"android:textSize="20sp"/><EditText android:id="@+id/etname"android:singleLine="true"android:layout_width="250dp"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:hint="请输入昵称"/></LinearLayout><LinearLayout android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"><TextView android:id="@+id/tv2"android:layout_width="50dp"android:layout_height="wrap_content"android:layout_marginTop="15dp"android:text="性别"android:textSize="20sp" /><RadioGroupandroid:id="@+id/rgsex"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal" ><RadioButton android:id="@+id/rbman"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="男"></RadioButton><RadioButton android:id="@+id/rbwoman"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="女"></RadioButton></RadioGroup></LinearLayout><LinearLayoutandroid:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1" ><TextView android:id="@+id/tv3"android:layout_width="50dp"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:text="账号"android:textSize="20sp" /><EditText android:id="@+id/etuser"android:singleLine="true"android:layout_width="250dp"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:hint="请输入账号”/></LinearLayout><LinearLayoutandroid:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1" ><TextView android:id="@+id/tv4"android:layout_width="50dp"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:text="密码"android:textSize="20sp"/><EditText android:id="@+id/etpsd"android:singleLine="true"android:layout_width="250dp"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:hint="请输入密码"android:inputType="textPassword"/></LinearLayout><LinearLayoutandroid:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"><TextView android:id="@+id/tv5"android:layout_width="50dp"android:layout_height="wrap_content"android:layout_marginTop="16dp"android:text="再次输入密码"android:textSize="15sp"/><EditTextandroid:id="@+id/etpsd2"android:singleLine="true"android:layout_width="250dp"android:layout_height="wrap_content"android:layout_marginTop="20dp"android:hint="请再次输入"android:inputType="textPassword"/></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_weight="1"android:orientation="horizontal" ><Buttonandroid:id="@+id/btLogin"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="100dp"android:text="登录" /></LinearLayout>
</LinearLayout>

已发布:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class RegisterActivity extends Activity implements OnClickListener{ protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.register);Button bt1 = (Button) findViewById(R.id.btn1);Button bt2 = (Button) findViewById(R.id.btn2);bt1.setOnClickListener(this);bt2.setOnClickListener(this);}public void onClick(View v) {// TODO Auto-generated method stubswitch(v.getId()){case R.id.btn1:Intent intent = new Intent();intent.setClass(RegisterActivity.this,NewActivity.class);startActivity(intent);break;case R.id.btn2:Intent intent2 = new Intent();intent2.setClass(RegisterActivity.this, MainActivity.class);startActivity(intent2);break;}}
}
Register.xml:
<?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"android:background="@drawable/j"><LinearLayoutandroid:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"> <TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="我的微博主页"android:textSize="30sp"android:layout_marginLeft="80dp" /></LinearLayout><LinearLayout android:orientation="horizontal"android:layout_width="fill_parent"android:layout_height="match_parent"android:layout_weight="1"><TextView android:layout_width="fill_parent"android:layout_height="match_parent"android:layout_marginTop="20dp"android:text="2014/03/02 08:08                                                   今天第一天开通微博"android:textColor="#FF0000"android:textSize="20sp" /></LinearLayout><LinearLayout android:orientation="horizontal"android:layout_width="fill_parent"android:layout_height="match_parent"android:layout_weight="1"><TextView android:layout_width="fill_parent"android:layout_height="match_parent"android:layout_marginTop="20dp"android:text="2014/03/12 22:22                             今天是我的生日,过的非常开心!"android:textColor="#FF0000"android:textSize="20sp" /></LinearLayout><LinearLayout android:orientation="horizontal"android:layout_width="fill_parent"android:layout_height="match_parent"android:layout_weight="1"><Button android:id="@+id/btn1"android:layout_width="fill_parent"android:layout_height="match_parent"android:layout_weight="1"android:layout_marginTop="20dp"android:text="发布新微博"android:textSize="20sp"/><Button android:id="@+id/btn2"android:layout_width="fill_parent"android:layout_height="match_parent"android:layout_weight="1"android:layout_marginTop="20dp"android:text="返回"android:textSize="20sp"/></LinearLayout>
</LinearLayout>

发布新微博

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class NewActivity  extends Activity  {EditText et;TextView tv;Button bt;final int MAX = 300;int rest = MAX;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.newsendb);bt = (Button) findViewById(R.id.submit);et = (EditText) findViewById(R.id.etsend);tv = (TextView) findViewById(R.id.tvleave);tv.setText("最多能输入"+rest+"个字符");bt.setOnClickListener(new OnClickListener() {public void onClick(View arg0) {// TODO Auto-generated method stubIntent intent = new Intent();intent.setClass(NewActivity.this, MainActivity.class);startActivity(intent);}});et.addTextChangedListener(new TextWatcher() {@Overridepublic void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {rest = MAX - et.getText().length();}public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,int arg3) {}public void afterTextChanged(Editable arg0) {if(rest > 0)tv.setText("还可以输入"+rest+"个字符");elsetv.setText("已经超过"+-rest+"个字符");}});}
newsendb.xml
<?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"android:background="@drawable/wbz">
<TextView android:id="@+id/tvxx"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="请你发布新微博,内容要健康,不得有反共倾向。不得有言语攻击行为,一经查实,后果自负! "android:textColor="#FF0000"android:singleLine="true"android:focusable="true"android:ellipsize="marquee"android:focusableInTouchMode="true"android:marqueeRepeatLimit="marquee_forever" /><EditText android:id="@+id/etsend"android:layout_width="fill_parent"android:layout_height="230dp"android:hint="请输入要发布的内容"/>
<TextView android:id="@+id/tvleave"android:layout_width="fill_parent"android:layout_height="wrap_content" /> <Button android:id="@+id/submit"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="提交” />
</LinearLayout


 

 

 

 

 

 


 


这篇关于Android端的微博项目的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1127155

相关文章

Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)

《Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)》文章介绍了如何使用dhtmlx-gantt组件来实现公司的甘特图需求,并提供了一个简单的Vue组件示例,文章还分享了一... 目录一、首先 npm 安装插件二、创建一个vue组件三、业务页面内 引用自定义组件:四、dhtmlx

SpringBoot项目注入 traceId 追踪整个请求的日志链路(过程详解)

《SpringBoot项目注入traceId追踪整个请求的日志链路(过程详解)》本文介绍了如何在单体SpringBoot项目中通过手动实现过滤器或拦截器来注入traceId,以追踪整个请求的日志链... SpringBoot项目注入 traceId 来追踪整个请求的日志链路,有了 traceId, 我们在排

Android开发中gradle下载缓慢的问题级解决方法

《Android开发中gradle下载缓慢的问题级解决方法》本文介绍了解决Android开发中Gradle下载缓慢问题的几种方法,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、网络环境优化二、Gradle版本与配置优化三、其他优化措施针对android开发中Gradle下载缓慢的问

部署Vue项目到服务器后404错误的原因及解决方案

《部署Vue项目到服务器后404错误的原因及解决方案》文章介绍了Vue项目部署步骤以及404错误的解决方案,部署步骤包括构建项目、上传文件、配置Web服务器、重启Nginx和访问域名,404错误通常是... 目录一、vue项目部署步骤二、404错误原因及解决方案错误场景原因分析解决方案一、Vue项目部署步骤

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

golang内存对齐的项目实践

《golang内存对齐的项目实践》本文主要介绍了golang内存对齐的项目实践,内存对齐不仅有助于提高内存访问效率,还确保了与硬件接口的兼容性,是Go语言编程中不可忽视的重要优化手段,下面就来介绍一下... 目录一、结构体中的字段顺序与内存对齐二、内存对齐的原理与规则三、调整结构体字段顺序优化内存对齐四、内

Android里面的Service种类以及启动方式

《Android里面的Service种类以及启动方式》Android中的Service分为前台服务和后台服务,前台服务需要亮身份牌并显示通知,后台服务则有启动方式选择,包括startService和b... 目录一句话总结:一、Service 的两种类型:1. 前台服务(必须亮身份牌)2. 后台服务(偷偷干

配置springboot项目动静分离打包分离lib方式

《配置springboot项目动静分离打包分离lib方式》本文介绍了如何将SpringBoot工程中的静态资源和配置文件分离出来,以减少jar包大小,方便修改配置文件,通过在jar包同级目录创建co... 目录前言1、分离配置文件原理2、pom文件配置3、使用package命令打包4、总结前言默认情况下,

python实现简易SSL的项目实践

《python实现简易SSL的项目实践》本文主要介绍了python实现简易SSL的项目实践,包括CA.py、server.py和client.py三个模块,文中通过示例代码介绍的非常详细,对大家的学习... 目录运行环境运行前准备程序实现与流程说明运行截图代码CA.pyclient.pyserver.py参

Android kotlin语言实现删除文件的解决方案

《Androidkotlin语言实现删除文件的解决方案》:本文主要介绍Androidkotlin语言实现删除文件的解决方案,在项目开发过程中,尤其是需要跨平台协作的项目,那么删除用户指定的文件的... 目录一、前言二、适用环境三、模板内容1.权限申请2.Activity中的模板一、前言在项目开发过程中,尤