Android Studio كيفية إنشاء تطبيق PDF Book
في هذه المقالة ، أريد أن أوضح لك كيفية إنشاء
تطبيق PDF Book. على منصة لذلك
للحصول على شرح جيد يمكنك مشاهدة الفيديو لهذه المقالة.
لنبدأ الآن!
1- أولاً
وقبل كل شيء ، قم بإنشاء مشروع جديد في Android
Studio الخاص بك ، واختر Empty
Activity أيضًا واعط اسما لهذا
المشروع.
2- حسنًا
بعد إنشاء مشروعنا في Android Studio ، تحتاج إلى فتح ملف build.gradle (الوحدة: التطبيق) وإضافة هذه المكتبة في قسم التبعية. لأن
هذه هي المكتبة التي سنستخدمها لقراءة ملف pdf الخاص بنا.
|
1 |
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2' |
بعد إضافة (الوحدة: التطبيق) الى ملف build.gradle فسيبدو الامر هكذا:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
apply
plugin: 'com.android.application' android
{ compileSdkVersion
28 defaultConfig
{ applicationId
"com.forogh.parwiz.pdfdocs" minSdkVersion
19 targetSdkVersion
28 versionCode
1 versionName
"1.0" testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner" } buildTypes
{ release
{ minifyEnabled
false proguardFiles
getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation
fileTree(dir: 'libs', include: ['*.jar']) implementation
'com.android.support:appcompat-v7:28.0.0-alpha1' implementation
'com.android.support.constraint:constraint-layout:1.1.0' implementation
'com.github.barteksc:android-pdf-viewer:2.8.2' testImplementation
'junit:junit:4.12' androidTestImplementation
'com.android.support.test:runner:1.0.2' androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2' } |
قم بعمل مزامنة sync
3- في ملف Andtoid M anufest.xml قم بزيادة هذه الاضافة كما يلي :
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
4 بعد ذلك , افتح ملف main_activity.xml وأضف هذا الرمز ، سنقوم هنا بشكل أساسي بإنشاء ملف PDFView ، وقد استخدمنا العرض والارتفاع كـ match_parent.
|
1 2 3 4 5 6 |
<com.github.barteksc.pdfviewer.PDFView android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/pdfViewer" /> |
بعد إضافة PDFView ، يبدو ملف activity_main.xml الخاص بنا على هذا النحو ، يمكنك أن ترى أننا نستخدم ConstraintLayout لهذا الغرض.
tivity_main.xml
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?xml
version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.github.barteksc.pdfviewer.PDFView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pdfbook">
</com.github.barteksc.pdfviewer.PDFView> </LinearLayout> </android.support.constraint.ConstraintLayout> |
5- افتح الآن MainActivity.java أولاً أنشئ كائن PDFView وبعد ذلك أضف هذا الرمز. في هذا الكود ، أنشأنا أولاً كائنًا
من فئة PDFView الخاصة بنا
، وبعد ذلك وجدنا معرف PDFView في ملف xml ، كما يمكنك
أن ترى أننا أضفنا بعض الميزات لـ PDFViewer.
pdfview =
findViewById(R.id.pdfViewer);
pdfview.useBestQuality(true);
pdfview.enableSwipe(true);
pdfview.fitToWidth();
pdfview.fromAsset("androidbook.pdf").load();
بعد إضافة الكود سيبدو MainActivity.java هكذا
import
android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import
com.github.barteksc.pdfviewer.PDFView;
public class MainActivity extends
AppCompatActivity {
private
PDFView pdfview;
@Override
protected void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PDFView pdfView= (PDFView)
findViewById(R.id.pdfbook);
pdfView.fromAsset("Title_Book.pdf").load();
}
}
6- قم الآن
بتشغيل المشروع بالكامل وستكون هذه هي النتيجة
واليك
هذا الفيديو التعليمي الذي سيمكنك من فعل ذلك :
الرابط :
