概述
水平有限,本文相当基础!!
自己从六月份断断续续的学习了一些android入门的知识。
至于为什么要学android,其实还是为了学习Java,对Java的不熟悉,使得学习了一些java知识之后不知道如何运用,所以选择了android来做一些可以看出效果的一些应用。
写这篇博客的目的,是为了对android知识的进行总结和巩固。一边写一边对原来代码进行优化。
之后会把重心继续放在java上。
这个app界面是本着模仿学校里一个常用软件来做的,因为能力不足,功能有很大不同。
这个app也是从我学android就开始做的,然后在一点点加新学的东西进去。所以有些地方不规范也是这个原因。可以看出很多新手菜鸟的影子。
粗略把结构分成了这样
首先自定义一个MyApplication继承Application,完成一个获取context的方法,方便后面在需要用的地方可以直接使用MyApplication.getContext()方法直接获取context。(虽然我每次都忘了用)
有的地方不建议将Context定义成静态的,具体原因我还没有深入了解,这个方法是真的很方便。
public class MyApplication extends Application {
private static Context context;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
public static Context getContext()
{
return context;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
再开始第一个页面时,在配置文件中values中的style里把actionBar改为NoActionBar。设置为隐藏actionbar。
设置在应用开始后先进入一个欢迎页面在进入main页面
public class WelcomeActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weclome);
Timer timer=new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
toMain();
}
},2000);
}
private void toMain() {
startActivity(new Intent(WelcomeActivity.this,MainActivity.class));
finish();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableTop="@mipmap/iswust"
android:gravity="center"
android:text="爱西科生活"
android:textColor="#000"
android:textStyle="bold"
android:textSize="30sp"
/>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 这样欢迎页面就算完成。
然后就是开始第一个界面吧,先是登录界面的布局。
activity_main.xml
最开始学的线性布局所以这个界面就是用线性布局写的
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="15dp">
<EditText
android:layout_width="0dp"
android:background="@drawable/bac_1"
android:padding="8dp"
android:layout_height="wrap_content"
android:drawableLeft="@mipmap/ic_login_code_icon"
android:layout_weight="3"
android:layout_marginLeft="30dp"
android:hint="验证码"
/>
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="50dp"
android:text="获取验证码"
android:layout_marginRight="30dp"
android:textColor="@android:color/white"
android:background="@drawable/bac_2"
android:layout_marginLeft="15dp"/>
</LinearLayout>
<Button
android:id="@+id/btn_login1"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginTop="20dp"
android:textSize="20sp"
android:textColor="@android:color/white"
android:background="@drawable/bac_2"
android:layout_gravity="center_horizontal"
android:text="登录/注册"/>
<TextView
android:id="@+id/in"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="使用旧版登录接口"
android:clickable="true"
android:textColor="#5382D2"/>
<TextView
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:text="——————第三方登录——————"/>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="@mipmap/wechat"
android:gravity="center"
android:text="微信" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:drawableTop="@mipmap/qq"
android:gravity="center"
android:text="QQ"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
>
<TextView
android:text="登录即代表同意"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="《服务协议》"
android:textColor="#7D9BD7"/>
</LinearLayout>
最后
以上就是坚定小土豆为你收集整理的对自己android小项目的一个归纳总结的全部内容,希望文章能够帮你解决对自己android小项目的一个归纳总结所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复