-
2018-10-09 17:21:10
1.沉浸状态栏(半透明效果):
直接将下面的代码放在activity中的setContentView(R.layout.activity_main);中之前就行了
if (Build.VERSION.SDK_INT >= 21) { View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); getWindow().setStatusBarColor(Color.TRANSPARENT); }
更多相关内容 -
android实例教程
2012-10-17 10:23:28简单实例开发教程,从最基础知识点入手,适合菜鸟级开发者使用。 -
Android实例教程
2010-03-01 15:22:04是入门很好的教程,全貌、细致...... -
android实例教程_Android内部存储示例教程
2020-07-06 11:34:52android实例教程Today we will look into android internal storage. Android offers a few structured ways to store data. These include 今天,我们将研究android内部存储。 Android提供了一些结构化的方式来存储...android实例教程
Today we will look into android internal storage. Android offers a few structured ways to store data. These include
今天,我们将研究android内部存储。 Android提供了一些结构化的方式来存储数据 。 这些包括
- Shared Preferences 共享首选项
- Internal Storage 内部存储器
- External Storage 外置储存
- SQLite Storage SQLite存储
- Storage via Network Connection(on cloud) 通过网络连接存储(在云上)
In this tutorial we are going to look into the saving and reading data into files using Android Internal Storage.
在本教程中,我们将研究如何使用Android Internal Storage将数据保存和读取到文件中。
Android内部存储 (Android Internal Storage)
Android Internal storage is the storage of the private data on the device memory. By default, saving and loading files to the internal storage are private to the application and other applications will not have access to these files. When the user uninstalls the applications the internal stored files associated with the application are also removed. However, note that some users root their Android phones, gaining superuser access. These users will be able to read and write whatever files they wish.
Android内部存储是设备内存中私有数据的存储。 默认情况下,将文件保存和加载到内部存储是应用程序专用的,其他应用程序将无法访问这些文件。 当用户卸载应用程序时,与该应用程序关联的内部存储文件也将被删除。 但是,请注意,某些用户会扎根其Android手机,从而获得超级用户访问权限。 这些用户将能够读取和写入所需的任何文件。
在Android内部存储中读取和写入文本文件 (Reading and Writing Text File in Android Internal Storage)
Android offers
openFileInput
andopenFileOutput
from the Java I/O classes to modify reading and writing streams from and to local files.Android从Java I / O类提供
openFileInput
和openFileOutput
,以修改本地文件之间的读写流。- openFileOutput(): This method is used to create and save a file. Its syntax is given below:
FileOutputStream fOut = openFileOutput("file name",Context.MODE_PRIVATE);
The method
openFileOutput() :此方法用于创建和保存文件。 其语法如下:openFileOutput()
returns an instance ofFileOutputStream
. After that we can call write method to write data on the file. Its syntax is given below:FileOutputStream fOut = openFileOutput("file name",Context.MODE_PRIVATE);
方法
openFileOutput()
返回FileOutputStream
一个实例。 之后,我们可以调用write方法在文件上写入数据。 其语法如下: - openFileInput(): This method is used to open a file and read it. It returns an instance of FileInputStream. Its syntax is given below:
FileInputStream fin = openFileInput(file);
After that, we call read method to read one character at a time from the file and then print it. Its syntax is given below:
In the above code, string temp contains all the data of the file.
openFileInput() :此方法用于打开文件并读取它。 它返回FileInputStream的实例。 其语法如下:FileInputStream fin = openFileInput(file);
之后,我们调用read方法从文件中一次读取一个字符,然后打印它。 其语法如下:
在上面的代码中,字符串temp包含文件的所有数据。
- Note that these methods do not accept file paths (e.g. path/to/file.txt), they just take simple file names. 请注意,这些方法不接受文件路径(例如path / to / file.txt),它们仅使用简单的文件名。
Android内部存储项目结构 (Android Internal Storage Project Structure)
Android内部存储示例代码 (Android Internal Storage Example Code)
The xml layout contains an
EditText
to write data to the file and a Write Button and Read Button. Note that theonClick
methods are defined in the xml file only as shown below:xml布局包含用于将数据写入文件的
EditText
以及“写入按钮”和“读取按钮”。 请注意,仅在xml文件中定义onClick
方法,如下所示:activity_main.xml
activity_main.xml
<RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android" xmlns:tools="https://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:padding="5dp" android:text="Android Read and Write Text from/to a File" android:textStyle="bold" android:textSize="28sp" /> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_below="@+id/textView1" android:layout_marginTop="22dp" android:minLines="5" android:layout_margin="5dp"> <requestFocus /> </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Write Text into File" android:onClick="WriteBtn" android:layout_alignTop="@+id/button2" android:layout_alignRight="@+id/editText1" android:layout_alignEnd="@+id/editText1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Read Text From file" android:onClick="ReadBtn" android:layout_centerVertical="true" android:layout_alignLeft="@+id/editText1" android:layout_alignStart="@+id/editText1" /> </RelativeLayout>
The
MainActivity
contains the implementation of the reading and writing to files as it was explained above.MainActivity
包含对文件进行读写的实现,如上所述。package com.journaldev.internalstorage; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.widget.EditText; import android.widget.Toast; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class MainActivity extends Activity { EditText textmsg; static final int READ_BLOCK_SIZE = 100; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textmsg=(EditText)findViewById(R.id.editText1); } // write text to file public void WriteBtn(View v) { // add-write text into file try { FileOutputStream fileout=openFileOutput("mytextfile.txt", MODE_PRIVATE); OutputStreamWriter outputWriter=new OutputStreamWriter(fileout); outputWriter.write(textmsg.getText().toString()); outputWriter.close(); //display file saved message Toast.makeText(getBaseContext(), "File saved successfully!", Toast.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } } // Read text from file public void ReadBtn(View v) { //reading text from file try { FileInputStream fileIn=openFileInput("mytextfile.txt"); InputStreamReader InputRead= new InputStreamReader(fileIn); char[] inputBuffer= new char[READ_BLOCK_SIZE]; String s=""; int charRead; while ((charRead=InputRead.read(inputBuffer))>0) { // char to string conversion String readstring=String.copyValueOf(inputBuffer,0,charRead); s +=readstring; } InputRead.close(); textmsg.setText(s); } catch (Exception e) { e.printStackTrace(); } } }
Here, a toast is displayed when data is successfully written into the internal storage and the data is displayed in the EditText itself on reading the data from the file.
在此,当成功将数据写入内部存储器时,将显示祝酒词,并且在从文件中读取数据时,数据将显示在EditText本身中。
The image shown below is the output of the project. The image depicts text being written to the internal storage and on clicking Read it displays back the text in the same EditText.
下图是项目的输出。 该图像描述了写入内部存储器的文本,单击“读取”后,它将在同一EditText中显示文本。
文件在哪里? (Where is the file located?)
To actually view the file open the Android Device Monitor from Tools->Android->Android Device Monitor.
The file is present in the folder data->data->{package name}->files as shown in the images below:
要实际查看文件,请从工具-> Android-> Android设备监视器中打开Android设备监视器。
该文件位于文件夹data-> data-> {package name}-> files中,如下图所示:
The file “mytextfile.txt” is found in the package name of the project i.e. com.journaldev.internalstorage as shown below:
在项目的程序包名称com.journaldev.internalstorage中可以找到文件“ mytextfile.txt” ,如下所示:
Download the final project for android internal storage example from below link.翻译自: https://www.journaldev.com/9383/android-internal-storage-example-tutorial
android实例教程
-
android最新实例教程修改版
2015-09-11 17:22:08详细介绍安卓开发的最新技术,和各个常用控件的使用说明,并附有代码段,让你轻松进行学习安卓开发。 -
黑马程序员_android实例教程
2015-11-06 14:27:28黑马程序员_android实例教程,网上找的的安卓教材,真心不错。 -
最详细的Android开发教程实例
2009-04-09 13:24:40目前为止最全、最详细的Android开发教程。 -
Android录音应用实例教程
2021-01-05 19:14:04本文以实例形式较为详细的展示了Android录音的实现方法,分享给大家供大家参考之用。具体方法如下: 首先是xml布局文件: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android xmlns:... -
Qt for Android开发实例教程
2020-09-04 05:58:42主要介绍了Qt for Android开发的方法,具有一定的参考借鉴价值,需要的朋友可以参考下 -
Android 实例教程
2012-07-27 15:22:541.android用户界面之AlarmManager教程实例汇总 http://www.apkbus.com/android-48405-1-1.html 2.android用户界面之文本编辑教程实例汇总 http://www.apkbus.com/android-48414-1-1.html 3.android用户界面之... -
安卓Android源码——开发API人脸检测实例教程.zip
2021-10-14 08:57:42安卓Android源码——开发API人脸检测实例教程.zip -
安卓Android源码——开发 API人脸检测实例教程.zip
2021-10-12 13:14:52安卓Android源码——开发 API人脸检测实例教程.zip -
android 实例 教程 例子
2009-08-31 19:42:45对于android平台上面的所有控件使用都有实例 及其强大!!!! 例子文件,想开发任何程序,都能从这些例子中找到 提示。已经整理成Myeclipse工程,导入即可使用 -
Android 开发 API人脸检测实例教程.zip项目安卓应用源码下载
2022-03-07 05:39:43Android 开发 API人脸检测实例教程.zip项目安卓应用源码下载Android 开发 API人脸检测实例教程.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考 -
Android开发之登录验证实例教程
2021-01-04 19:10:53本文所述实例源自一个项目开发中的登录验证功能,具体的要求就是,在Android端输入用户名和密码,在服务器端验证MySQL数据库中是否有此用户,实现之前当然首要的是,如何使Android端的数据发送到服务器端,具体的... -
安卓Android源码——精典源码之开发API人脸检测实例教程.zip
2021-10-14 08:57:54安卓Android源码——精典源码之开发API人脸检测实例教程.zip -
《Android 应用开发案例教程》PDF
2018-08-20 16:40:30《android应用开发案例教程》注重理论与实践相结合,内容详尽,提供了大量实例,突出应用能力的培养,将一个实际项目的知识点分解在各章作为案例讲解,是一本实用性突出的教材。本书可作为普通高等学校计算机专业本... -
Android应用源码之开发 API人脸检测实例教程.zip项目安卓应用源码下载
2022-03-08 16:50:47Android应用源码之开发 API人脸检测实例教程.zip项目安卓应用源码下载Android应用源码之开发 API人脸检测实例教程.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目... -
Android利用zxing快速集成二维码扫描的实例教程
2021-01-04 08:31:12前言 大家应该都还记得,以前的我们常见的都是条形扫码,自从微信使用二维码扫描后,现在市场上基本都用二维码扫描,基本上每一个项目都会有一个二维码扫描,这篇就简单快速的实现一个扫描效果,让我们对二维码的... -
Android 2.0游戏开发实践实例教程+源码
2018-01-03 09:39:02Android 2.0游戏开发实践实例教程+源码,资源总大小,1GB -
Android中编写简单的手电筒小应用的实例教程
2021-01-05 15:52:42主要实现两个步骤: 1、实现打开和关闭闪光灯;而实现操作闪光灯主要通过Camera类 Camera camera = Camera.open(); Parameters mParameters = camera.getParameters(); mParameters.setFlashMode(Camera.... -
Flutter中嵌入Android 原生TextView实例教程
2021-01-21 19:36:25本篇文章 中写到的是 flutter 调用了Android 原生的 TextView 案例 添加原生组件的流程基本上可以描述为: 1 android 端实现原生组件PlatformView提供原生view 2 android 端创建PlatformViewFactory用于生成Platform... -
Android App中自定义View视图的实例教程
2021-01-05 04:57:23很多的Android入门程序猿来说对于Android自定义View,可能都是比较恐惧的,但是这又是高手进阶的必经之路,所有准备在自定义View上面花一些功夫,多写一些文章。先总结下自定义View的步骤: 1、自定义View的属性 2、... -
Android程序设计经典教程 pdf
2017-10-17 10:37:27左军主编的这本《Android程序设计经典教程》 从初学者的角度出发,通过通俗易懂的语言、丰富多 彩的实例介绍了Android程序开发的各方面技术。本 书在介绍Android技术的同时,提供一些经典案例, 通过经典案例让读者... -
Android系统中的蓝牙连接程序编写实例教程
2021-01-04 22:05:35frameworks/base/core/java/android/bluetooth/ 包含了bluetooth的JAVA类。 2、JNI层 frameworks/base/core/jni/android_bluetooth_开头的文件 定义了bluez通过JNI到上层的接口。 frameworks/base/core/jni/android_... -
Android App中使用ListFragment的实例教程
2021-01-04 16:51:39因此,在ListFragment对应的布局文件中,必须指定一个 android:id 为 “@android:id/list” 的ListView控件! ListFragment基础使用 下面介绍在Activity中显示ListFragment的步骤。 1. Activity对应的代码 publi