目录结构
src: 存放java代码
gen: 存放自动生成文件的. R.java 存放res文件夹下对应资源的id
project.properties: 指定当前工程采用的开发工具包的版本
libs: 当前工程所依赖的jar包.
assets: 放置一些程序所需要的媒体文件.
bin: 工程的编译目录. 存放一些编译时产生的临时文件和当前工程的.apk文件.
res(resources): 资源文件.
drawable: 存放程序所用的图片.
layout: 存放android的布局文件.
fragment_main.xml(这个是新API的新布局结构)
activity_main.xml(主布局)
menu: 存放android的OptionsMenu菜单的布局.
values (应用程序所需要的数据. 会在R文件中生成id)
strings.xml 存放android字符串.
dimens.xml 存放屏幕适配所用到的尺寸.
style.xml 存放android下显示的样式.
分辨率:
values-sw600dp 7寸平板所对应的值
values-sw720dp-land 10寸平板所对应的值
values-v11 指定3.0版本以上的手机显示的样式.
values-v14 指定4.0版本以上的手机显示的样式.
AndroidManifest.xml: android应用程序的入口文件. 声明了android里边的组件. 和相关配置信息.
proguard-project.txt: 加密当前程序所使用.
adb命令
adb android debug bridge android调试桥
adb devices 列出所有的设备
adb start-server 开启adb服务
adb kill-server 关闭adb服务
adb logcat 查看Log
adb shell 挂载到Linux的空间(可以使用Linux命令)
adb install <应用程序(加扩展名)> 安装应用程序
adb –s <模拟器名称> install <应用程序(加扩展名)> 安装应用到指定模拟器
adb uninstall <程序包名>
adb pull <remote> <local>
adb push <local> <remote>
emulator –avd <模拟器名称>
ctrl + F11 横竖屏的切换
拨号器实现
拨号器是个很简单的布局,用来做Android的入门最好不过。
本程序给予Android API19编译实现,因此是新版布局。不习惯的请注意。
1、Java主程序
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
public void call(View v){
System.out.println("拨打电话。");
//读取号码
EditText editText=(EditText) findViewById(R.id.eal);
String string=editText.getText().toString();
//拨号
Intent intent=new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+string));
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
}
}
2、主清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.caller"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<uses-permission
android:name="android.permission.CALL_PHONE"
/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.caller.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>
3、布局清单主Activity
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.caller.MainActivity"
tools:ignore="MergeRootFrame" />
4、布局XML文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/cal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cal"
/>
<EditText
android:id="@+id/eal"
android:inputType="number"
android:layout_below="@+id/cal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/bal"
android:onClick="call"
android:layout_below="@+id/eal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bal"
/>
</RelativeLayout>