前言

大家好,我是 Vic,今天给大家带来Android精通教程V的概述,希望你们喜欢

封面

前言

如果你想学习Android开发,那你就要了解Java编程,这是基础,也是重点,如果没学Java语法就先学习,再来学Android,别问可不可以先学Android,都告诉了,先学Java对吧!

Android开发的基本了解

Android开发主要了解这四种重要组件:

  • activity为用户界面,就是说activity可以构成用户界面。
  • ContentProvider是为了设备中存储的数据,通过创建ContentProvider来实现数据共享。
  • Service是运行在后台的任务,无需用户直接与之交互。
  • Intent是一种行为描述机制(如选择照片,打电话等)。在Android中,几乎一切都是通过Intent来实现的,这给我们提供了大量替换或重用组件的机会。

描述Android项目结构

AndroidManifest.xml:是一个xml文件,描述了被构建的应用程序。
assets:文件夹是为了存放需要打包到应用程序的静态文件。
bin:文件夹是为了存放编译过后的应用程序。
gen:文件夹为了存放生成的源代码。
libs:文件夹是存放第三方包的jar文件。
src:文件夹是程序的Java源代码。
res:文件夹存放的是应用程序的资源。
在res文件夹中:
res/drawable/:存放的是图像
res/layout/:存放是基于xml的文件。
res/menu/:存放的是基于xml的菜单文件。
res/raw/:存放的是通用的文件。
res/valuse/:存放的是字符串。
res/xml/:是通用的xml的文件。
在bin文件夹中:
bin/classes/:存放的是编译后的Java类文件。
在AndroidManifest.xml文件中:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="cn.edu.gdmec.android.androidstudiodemo"><!--原为android:theme="@style/AppTheme"--><!--去除ActionBar标题栏--><!--添加应用图标,app_icon--><applicationandroid:allowBackup="true"android:icon="@drawable/app_icon"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.AppCompat.NoActionBar"><activity android:name=".MainActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><!--添加实现类--><activity android:name=".######"></activity></application>
</manifest>

了解一下build.gradle(app)

apply plugin: 'com.android.application'android {compileSdkVersion 26defaultConfig {applicationId "cn.edu.gdmec.android.androidstudiodemo"minSdkVersion 19targetSdkVersion 26versionCode 1versionName "1.0"testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"}buildTypes {release {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}
}dependencies {implementation fileTree(dir: 'libs', include: ['*.jar'])implementation 'com.android.support:appcompat-v7:26.1.0'implementation 'com.android.support.constraint:constraint-layout:1.0.2'testImplementation 'junit:junit:4.12'androidTestImplementation 'com.android.support.test:runner:1.0.1'androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

了解基本布局的部件

TextView:了解android:typeface,android:textStyle,android:textColor.
EditText:编辑框android:autoText,android:capitalize,android:digitas,android:singleLine.
内边距:android:paddingLeft,android:paddingRight,android:paddingTop,android:paddingBottom
RelativeLayout布局:android:layout_alignParentTop,android:layout_alignParentBottom,android:layout_alignParentLeft,android:layout_alignParentRight,android:layout_centerHorizontal,android:layout_centerVertical,android:centerHorizontal,android:layout_centerInParent.
android:layout_above,android:layout_below,android:layout_toLeftOf,android:layout_toRightOf,android:layout_alignTopandroid:layout_alignBottom,android:layout_alignLeft,android:layout_alignRight,android:layout_alignBaseline.
TableLayout布局:
android:stretchColumns,android:shrinkColumns,android:collapseColumns.

//TableLayout
<TableLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:stretchColumns="1"><TableRow><TextViewandroid:text="姓名:"/><EditTextandroid:id="@+id/xm"android:layout_span="3"/></TableRow><Viewandroid:layout_height="2px"android:background="#000000"/><TableRow><Buttonandroid:id="@+id/xx"android:layout_column="2"android:text="消除"/><Buttonandroid:id="@+id/submit"android:text="发送"/></TableRow>
</TableLayout>

适配器

Sting[] items={"h","j","k","a","s","d","b"};
new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,items);
<?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">
<TextViewandroid:id="@+id/selection"android:layout_width="match_parent"android:layout_height="wrap_content"/>
<ListViewandroid:id="@android:id/list"android:layout_width="match_parent"android:layout_height="match_parent"android:drawSelectiorOnTop="false"/>
</LinearLayout>
public class ListViewDemo extends ListActivity{TextView selection;String[] items={"a","b","c","d","e","f","g"};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);setListAdapter(new ArrayAdapter<String>(this,android.R.layout_simple_list_item_1,items));selection= findViewById(R.id.selection);
}public void onListItemClick(ListView parent,View v,int position,long id){selection.setText(items[position]);}
}

网格

GridView:android:numColumns,android:verticalSpacing,android:horizontalSpacing,android:columnWidth,android:stretchMode.

//适配器
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent">
<TextViewandroid:id="@+id/selection"android:layout_width="match_parent"android:layout_height="wrap_content"/>
<AutoCompleTextViewandroid:id="@+id/auto"android:layout_width="match_parent"android:layout_height="wrap_content"android:completionThreshold="3"/>
</LinearLayout>
public class AutoCompleteDemo extends Activity implements TextWatcher{TextView selection;AutoCompleteTextView auto;String[] items={"aaav","bbbv","cccv","dddv","eeev","fffv","gggv"};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);selection=findViewById(R.id.selection);auto=findViewById(R.id.auto);auto.addTextChangedListener(this);auto.setAdapter(new ArrayAdapter<String>(this,android.R.layout_simple_item_1,items));
}public void onTextChanged(CharSequence s, int start, int before, int count){selection.setText(auto.getText());
}
}

Gallery

Gallery:android:spacing,android:spinnerSelector,android:drawSelectorOnTop

//适配器
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://echema.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal">
<ImageViewandroid:id="@+id/icon"android:layout_width="20px"android:layout_height="wrap_content"android:paddingLeft="2px"android:paddingRight="2px"android:paddingTop="2px"android:src="@drawable/image"/>
<TextViewandroid:id="@+id/label"android:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="20sp"/>
</LinearLayout>
public class Demo extends ListActivity{TextView selection;String[] items = { "aaaa","asdg","bsdes","slfl","wete","wetwd","sdfefs"};
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);setListAdapter(new ArrayAdapter<String>(this, R.layout.simple,R.id.label,items));selection=findViewById(R.id.selection);
}
public void onListItemClick(ListView parent,View v,int position,long id){selection.setText(items[position]);}
}
//动态的列表
public class Demo extends ListActivity{TextView selection;String[] items = { "aaaa","asdg","bsdes","slfl","wete","wetwd","sdfefs"};
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);setListAdapter(new IconAdapter());selection=findViewById(R.id.selection);
}
public void onListItemClick(ListView parent,View v,int position,long id){selection.setText(items[position]);}
class IconAdapter extends ArrayAdapter {IconAdapter(){super(Demo.this,R.layout.simple,items);}public View getView(int position, View convertView, ViewGrop parent){LayoutInflater inflater=getLayoutInflater();View simple = inflater.inflate(R.layout.simple,parent,false);TextView label=simple.findViewById(R.id.simple);label.setText(items[position]);ImageView icon = simple.findViewById(R.id.icon);icon.setImageResource(R.drawable.icon);
}

日期与时间

DatePickerDatePickerDialog->DatePickerDialog-->OnDateChangedListenerOnDateSetListener
TimePickerTimePickerDialog->TimePickerDialog-->OnTimeChangedListenerOnTimeSetListener
主要示例代码:

Calendar dateTime = Calendar.getInstance();
//日期
DatePickerDialog.OnDateSetListener d=new DatePickerDialog.OnDateSetListener(){public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth){dateTime.set(Calendar.YEAR,year);dateTime.set(Calendar.MONTH,monthOfYear);dateTime.set(Calendar.DAY_OF_MONTH,dayOfMonth);updateLabel();}
};
//时间
TimePickerDialog.OnTimeSetListener t=new TimePickerDialog.OnTimeSetListener(){public void onTimeSet(TimePicker view, int hourOfDay, int minute){dateTime.set(Calendar.HOUR_OF_DAY,hourOfDay);dateTime.set(Calender.MINUTE,minute);updateLabel();}
};
//日期的点击按钮
Button btn=findViewById(R.id.date);
btn.setOnClickListener(new View.OnClickListener(){public void onClick(View v){new DatePickerDialog(Demo.this,d,dateTime.get(Calendar.YEAR),dateTime.get(Calendar.MONTH),dateTime.get(Calendar.DAY_OF_MONTH)).show();}
});
//时间的点击按钮
Button btn=findViewById(R.id.time);
btn.setOnClickListener(new View.OnClickListener(){public void onClick(View v){new TimePickerDialog(Demo.this,t,dateTime.get(Calendar.HOUR_OF_DAY),dateTime.get(Calendar.MINUTE),true).show();}
});
//显示Calendar
dateTimetv.getTime();// dtl.format();

创建时钟

DigitalClockAnalogClock

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><AnalogClock android:id="@+id/analogclock"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_alginParentTop="true"/><DigitalClockandroid:id="@+id/digitalclock"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_below="@id/analogclock"/>
</RelativeLayout>

进度条(android.widget.ProgressBar)

进度条可以是水平的,也可以是旋转轮,你可以用incrementProgressBy()来增加进度,也可以用setProgress()来增加进度。

进度条有很多样式,Android提供了这些:

  • Widget.ProgressBar.Horizontal
  • Widget.ProgressBar.Small
  • Widget.ProgressBar.Large
  • Widget.ProgressBar.Inverse
    等。

android.widget.SeekBar
这个是ProgressBar的扩展,这个是可以滑动选择的进度形式。

用户可以通过 SeekBar.OnSeekBarChangeListener来操作滑块的位置。

适配器-android.widget.Adapter

它的子类有:arrayadapter,baseadpter,cursoradapter,listadapter,simpleadapter,spinneradapter

WebView

android.webkit.WebView
这里的WebView是显示网页的视图,当我们要在WebView中加载网页的时候,,我们要在android manifest.xml中添加权限。

<uses-permission android:name = “android.permission.INTERNET” />

如何用代码,以下显示:

 Uri uri = Uri.parse(url);Intent intent = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent);

显示

WebView webview = new WebView(this);setContentView(webview);

进行加载:

webview.loadUrl(url);

显示框

public void onClick(View view){if(view==button1){new AlertDialog.Builder(this).setTitle("Message").setMessage("ok").setNeutralButton("Close", new DialogInterface.OnClickListener(){public void onClick(DialogInterface dialog, int in){}}).show();
}

总结

  • 本文讲了Android精通教程V,如果您还有更好地理解,欢迎沟通
  • 定位:分享 Android&Java知识点,有兴趣可以继续关注

Android精通教程V相关推荐

  1. android 教程概要,Android精通教程-第一节Android入门简介

    前言 大家好,我是 Vic,今天给大家带来Android精通教程-第一节Android入门简介的概述,希望你们喜欢 每日一句 If life were predictable it would cea ...

  2. Android精通教程-Android入门简介

    前言 大家好,我是 Vic,今天给大家带来Android精通教程-Android入门简介的概述,希望你们喜欢 每日一句 If life were predictable it would cease ...

  3. Android基础教程——从入门到精通(上)

    本文是对B站教程 动脑学院 Android教程 学习过程中所做的笔记. 文章分为上下两部分,此文是上部分,下部分链接为:Android基础教程--从入门到精通(下) 源视频教程并没有录制全,本文还补充 ...

  4. python语言入门与精通-终于懂得python从入门到精通教程

    对只用一种语言来构建某个项目的情况而言,Javascript和它的框架是非常有用的.Angular.js可以控制展示给用户的网站前端.Node.js将作为管理网站所有内容的网络服务器.Express. ...

  5. python从入门到精通-终于懂得python从入门到精通教程

    对只用一种语言来构建某个项目的情况而言,Javascript和它的框架是非常有用的.Angular.js可以控制展示给用户的网站前端.Node.js将作为管理网站所有内容的网络服务器.Express. ...

  6. Android Volley教程

    In this android volley tutorial, we'll be implementing the Volley library in our application. If you ...

  7. android实例教程_Android内部存储示例教程

    android实例教程 Today we will look into android internal storage. Android offers a few structured ways t ...

  8. android实例教程_活动之间的Android意向处理示例教程

    android实例教程 In our last Android Tutorial, we discussed the Android Hello World Application. In this ...

  9. Android Camera2 教程 · 第三章 · 预览

    Android Camera2 教程 · 第三章 · 预览 DarylGo关注 Android Camera 上一章<Camera2 开启相机>我们学习了如何开启和关闭相机,接下来我们来学 ...

最新文章

  1. 自然辩证法的当代价值
  2. Caffe学习笔记(4)--------用师兄的源码都差点没跑通觉得自己智商真的捉急!...
  3. 一个泛型冒泡排序的实现
  4. 优先级队列,代码参考范例
  5. Django REST framework介绍
  6. BGP——权重选路(讲解+配置命令)
  7. 【译】Effective TensorFlow Chapter11——在TensorFlow中调试模型
  8. jQuery AJAX 方法
  9. 推荐一个Oracle数据库学习网站
  10. 获取高德地图POI数据
  11. Linux efi分区被删除了,恢复删掉的 MSR 和 EFI 分区
  12. 十六进制颜色与RGB颜色转换
  13. Ubuntu burg
  14. excel单元格内容拆分_Excel技巧:如何批量合并相同内容单元格?
  15. 2020年有寓意的领证日期_2020年领证日期怎么选
  16. c语言既是素数又是回文数的三位数,编写程序,找出所有既是素数又是回文数的三位正整数.例如:131等...
  17. Python 数据分析学什么
  18. android 自动化 微信,C#手把手教你玩微信自动化
  19. 理解C++中花括号{}的作用
  20. 金蝶云星空与盘古MES系统数据集成对接方案

热门文章

  1. Ubuntu 下挂ISO到虚拟光驱的方法
  2. python 判断输入的字符,是字母,数字,还是其他字符
  3. 深夜里,程序员最喜欢去的网站竟然是 ...
  4. 谷歌10年,难说再见......
  5. 刀片服务器改台式电脑_刀片服务器安装指南_IT /计算机_信息
  6. SCA(successive convex approximation)学习
  7. xlsx文件打不开损坏要如何恢复呢?
  8. Android3D抽方块源码,block puzzle jewel 方块拼图消除游戏安卓源码
  9. 洛谷P1478 陶陶摘苹果(升级版)
  10. 搜索技巧:提升你的搜索效率