Android Create Article Book Review
1. Project Structure
2. Gradle
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.article.bookreview"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.balysv:material-ripple:1.0.2'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.mikhaellopez:circularimageview:3.2.0'
}
3. Main Activity
package com.article.bookreview;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.article.bookreview.utils.Tools;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_article_book_review);
initToolbar();
}
private void initToolbar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
toolbar.getNavigationIcon().setColorFilter(getResources().getColor(R.color.grey_5), PorterDuff.Mode.SRC_ATOP);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(null);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Tools.setSystemBarColor(this, R.color.grey_90);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_search, menu);
Tools.changeMenuIconColor(menu, getResources().getColor(R.color.grey_5));
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
} else {
Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
}
return super.onOptionsItemSelected(item);
}
}
4. Layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_90"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/grey_90"
app:contentInsetStartWithNavigation="0dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:theme="@style/Toolbar.Light">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large"
android:gravity="center"
android:minHeight="60dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pellentesque vel nibh"
android:textAllCaps="true"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:textColor="@android:color/white"
app:fontFamily="sans-serif-medium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Proin commodo porttitor"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="@color/grey_40" />
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/nested_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="none"
android:scrollingCache="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="250dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/image_32" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/overlay_dark_50" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-100dp"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:layout_width="110dp"
android:layout_height="160dp"
android:layout_gravity="end"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginRight="@dimen/spacing_large">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/spacing_middle"
android:scaleType="centerCrop"
android:src="@drawable/image_32" />
</androidx.cardview.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-60dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="@dimen/spacing_large">
<com.mikhaellopez.circularimageview.CircularImageView
android:id="@+id/image"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/photo_male_1"
app:civ_border="true"
app:civ_border_color="@color/grey_80"
app:civ_border_width="2dp"
app:civ_shadow="true"
app:civ_shadow_radius="0" />
<View
android:layout_width="@dimen/spacing_large"
android:layout_height="0dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anderson Thomas"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="@color/grey_5"
app:fontFamily="sans-serif-medium" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:layout_width="@dimen/spacing_middle"
android:layout_height="@dimen/spacing_middle"
android:layout_marginTop="@dimen/spacing_xsmall"
android:layout_marginEnd="@dimen/spacing_medium"
android:layout_marginRight="@dimen/spacing_medium"
android:tint="@color/grey_60"
app:srcCompat="@drawable/ic_location" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Istanbul, Turkey"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="@color/grey_60" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/overlay_dark_10" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/spacing_large">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_small"
android:text="Suspendisse"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="@color/grey_40" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Maecenas venen"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="@color/grey_5" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_small"
android:text="Phasellus"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="@color/grey_40" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Proin 1256"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="@color/grey_5" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/spacing_large">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_small"
android:text="Malesuada"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="@color/grey_40" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Etiam porttitor"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="@color/grey_5" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_small"
android:text="Magna"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="@color/grey_40" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Curabitur id"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="@color/grey_5" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/overlay_dark_10" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_middle"
android:layout_marginRight="@dimen/spacing_large"
android:text="Description"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/grey_40"
app:fontFamily="sans-serif-medium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_middle"
android:layout_marginRight="@dimen/spacing_large"
android:lineSpacingExtra="@dimen/spacing_small"
android:text="@string/long_lorem_ipsum_2"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@color/grey_5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/spacing_large"
android:layout_marginTop="@dimen/spacing_middle"
android:layout_marginRight="@dimen/spacing_large"
android:layout_marginBottom="@dimen/spacing_xlarge"
android:lineSpacingExtra="@dimen/spacing_small"
android:text="@string/long_lorem_ipsum"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@color/grey_5" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
5. Value
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:ns1="urn:oasis:names:tc:xliff:document:1.2">
<string name="appbar_scrolling_view_behavior" translatable="false">com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior</string>
<style name="ThemeOverlay.AppCompat.Dark.ActionBar" parent="Base.ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="TextAppearance.AppCompat.Subhead" parent="Base.TextAppearance.AppCompat.Subhead"/>
<style name="TextAppearance.AppCompat.Caption" parent="Base.TextAppearance.AppCompat.Caption"/>
<style name="TextAppearance.AppCompat.Body1" parent="Base.TextAppearance.AppCompat.Body1"/>
<style name="TextAppearance.AppCompat.Body2" parent="Base.TextAppearance.AppCompat.Body2"/>
<style name="TextAppearance.AppCompat.Medium" parent="Base.TextAppearance.AppCompat.Medium"/>
<color name="overlay_dark_10">#1A000000</color>
<color name="grey_5">#f2f2f2</color>
<color name="grey_40">#999999</color>
<color name="grey_60">#666666</color>
<color name="grey_80">#37474F</color>
<color name="grey_90">#263238</color>
</resources>