بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]
پرسش و پاسخ

آموزش متریال دیزاین خیلی ساده! هم در Eclipse و هم در AndroidStudio

مدیریت گفتگو
saeidhic 11 سال پیش
آخرین تغییر: 9 سال پیش

سلام دوستان 

طبق جستجویی که من کردم دیدم خیلی از دوستان دنبال تم متریال دیزاین برای برنامشون هستن 

خب توی گوگل اگه سرچ کرده باشید میبینید کلی آموزش هست اما گیج کننده هست

اینه که تصمیم گرفتم تم متریال رو بهتون آموزش بدم 

قبل از شروع فقط بگم که این آموزش برای اون دسته از افرادی هست که  از Androd Studio استفاده میکنن

توی اکلیپس هم میشه implement کرد و بهتون یاد میدم که چطور این کارو بکنید اما دردسراش زیاده طوری که خودتون ترجیح میدید از AndroidStudio استفاده کنید 

تا چند ساعت دیگه مطالبش رو جمع بندی میکنم  و براتون میذارم امید وارم که ازین آموزش بهره و لذت کافی رو ببرید

پس منتظر آموزش باشید :)

نظرات

mahdi2565 11 سال پیش
در اندروید استادیو که مشکلی نیست ولی اکلیپس انگار پدر کشتگی داره با متریال !!!!!!!!
Majid Arabi 11 سال پیش
دمت گَرم . . . اینطوری خیلی خوب میشه . . . مرسی (:
Hajhosseini 11 سال پیش
دوست عزیز کد هاتون رو اول توی notepad کپی کنید، بعد اینجا درج کنید که قابل خوندن باشن
saeidhic 11 سال پیش
ببخشید دوست عزیز من بلد نبودم الان اصلاح کردم :) ممنون بابت راهنماییت

پاسخ‌ها 24

saeidhic 11 سال پیش

خب بچه ها من اومدم ببخشید که یکم دیر شد آخه دیشب ساعت 4 این پست رو گذاشتم اولا که خواب بودم بعدم خودم یه مشکلی داشتم و بیرون رفته بودم


حالا اینا مهم نیست میریم سر آموزش ها :)

من اول Android Studio رو آموزش میدم چون برام راحت تره 

خب قدم اول این هست که شما در پوشه ی res و بعد  values یک فایل xml به نام colors ایجاد کنید مثل تصویر زیر کداشم براتون میذارم

اینم سورس کد هاش:


 <?xml version="1.0" encoding="utf-8"?>
<resources>
    <colorname="colorPrimary">#00C0FF</color>
    <colorname="colorPrimaryDark">#0080FF</color>
    <colorname="textColorPrimary">#FFFFFF</color>
    <colorname="windowBackground">#FFFFFF</color>
    <colorname="navigationBarColor">#000000</color>
    <colorname="colorAccent">#00FFFF</color>
</resources>

 

نظرات

alisherafat01 11 سال پیش
چجوری اون styles.xml(v21) برات ایجاد شده ؟ از من نمیاد هر کاری میکنم... راستی داری از لب تاب استفاده میکنی توی بعضی پنجره ها ارتفاع کم نمیاری؟
saeidhic 11 سال پیش

خب حالا وقت این رسیده که  تم شخصی خودمون رو بسازیم!
عه!مگه میشه تم شخصی هم ساخت؟بله چرا نشه فقط باید باباش تم appCompat خود اندروید باشه وگرنه با کلی ارور و کرش مواجه میشید.از من گفتن بود!

خب واسه این کار برید اول تو پوشه ی values بعد styles.xml رو باز کنید و مطابق زیر این کد هارو وارد کنید:

 <resources>

    <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
</style>

    <style name="MyMaterialTheme" parent="MyMaterialTheme.Base">

    </style>

    <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    </resources>

نظرات

saeidhic 11 سال پیش

خب امید وارم که مرحله ی قبل رو انجام داده باشید 

میریم مرحله ی بعد

روی پوشه ی res کلیک راست کنید و بعد روی android Resource Directory رو کلیک کنید

مطابق شکل زیر عمل کنید:


نظرات

saeidhic 11 سال پیش

حالا بیاید و رو پوشه ی values راست کلیک کنید و valus resource file رو کلیک کنید مطابق شکل زیر عمل کنید :

نظرات

saeidhic 11 سال پیش

خب حالا فایل activity_main.xml رو باز کنید توش این کد های زیر رو بزنید :

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="saeid.test.mystartup5.MainActivity" xmlns:app1="http://schemas.android.com/apk/res/saeid.test.mystartup5">
    
    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:local="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app1:navigationIcon="@drawable/ic_launcher"
        local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    <View
        android:layout_width="match_parent"
        android:layout_height="4dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/toolbar"
        android:background="@drawable/toolbar_elevation" />

</RelativeLayout>

این شکلی میشه :

نظرات

saeidhic 11 سال پیش

خب حالا MainActivity رو باز کنید و این کد هارو داخلش بزنید 

برنامه رو اجرا کنید تا ببینید چطوری کار میکنه :)

         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

نظرات

mahdi2565 11 سال پیش
برای شما از ActionBarActivity ایراد نگرفته ؟؟؟ همچین اروری به من داره ActionBarActivity is deprecated !!!!!!!!!
mahdi2565 11 سال پیش
بعد موقع اجرای کده setSupportActionBar ازم ایراد میگیره
mahdi2565 11 سال پیش
بعد موقع اجرای کده setSupportActionBar ازم ایراد میگیره
mahdi2565 11 سال پیش
بعد موقع اجرای کده setSupportActionBar ازم ایراد میگیره
saeidhic 11 سال پیش
مهدی جان ActionBarActivity دیگه دپریکیت depricate شده کدش دیگه مرده از AppCompatActivity استفاده کن :)
saeidhic 11 سال پیش

این تا این جای کار که با هم پیش رفتیم و تونستیم که اکشن بار رو با سایش درست کنیم

تو قدم های بعدی نحوه ی استفاده کردن از Recycler رو آموزش میدم

راستی شما میتونید برای همین تولبار آیکون برنامتونم بذارید چطوری؟

خیلی ساده!

رو تولبار کلیک کنید بعد قسمت propertice یه جا نوشته navigation icon روش یه آیکون بذارید خیلی ساده 

فقط من الان یکم خسته شدم یه استراحت کوچولو بعدش ادامه ی بحث رو جدی تر میریم جلو
فقط یکم کارمون از این لحظه به بعد سخت و گیج کننده میشه ولی میدونم شما میتونید و از عهدش بر میاید :)

امید وارم که تا این جای کار لذت برده باشید از آموزش ها :)

نظرات

Majid Arabi 11 سال پیش
دمت گرم با مرام :)
saeidhic 11 سال پیش

یکی از دوستان خوب سوال خوبی پرسیدن که من از کلاس ActionBarActivity استفاده میکنم

ببینید دوستان ActionBarActivity دیگه کد هاش مرده اصطلاحا depricate شده 

همه ی دوستان از AppCompatActivity استفاده کنن

دیگه ارور و خطاهاشون  برطرف میشه :)

نظرات

saeidhic 11 سال پیش

خب من اومدم :) بعد از یه استراحت کوچولو

ببینید بچه ها برای استفاده ازrecycler باید اول کتاب خونش رو با پروژه ی android studio سینک کنید میگم چطوری

وارد build.gradle پروژتون بشید و خط کد زیر رو به dependencies اضافه کنید 

به عکس هم توجه کنید:

compile 'com.android.support:recyclerview-v7:22.2.0'

نظرات

saeidhic 11 سال پیش

تو این مرحله من سورس کد های لایه هام رو براتون به اشتراک میذارم لایه هارو مثل من درست کنید:

لایه ی اول لایه ی toolbar.xml

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

لایه ی دوم nav_drawer_row.xml:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true">

    <TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textSize="15dp"
android:textStyle="bold" />

</RelativeLayout>

لایه ی سوم  fargment_navigation_drawer.xml:

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">


    <RelativeLayout
android:id="@+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_alignParentTop="true"
android:background="@color/colorPrimary">

        <ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/ic_profile"
android:scaleType="fitCenter"
android:layout_centerInParent="true" />

    </RelativeLayout>


    <android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_marginTop="15dp" />


</RelativeLayout>

لایه ی چهارم fragment_message.xml :

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="androidhive.info.materialdesign.activity.HomeFragment">


    <TextView
android:id="@+id/label"
android:layout_alignParentTop="true"
android:layout_marginTop="100dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="45dp"
android:text="MESSAGE"
android:textStyle="bold"/>

    <TextView
android:layout_below="@id/label"
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="Edit fragment_home.xml to change the appearance" />

</RelativeLayout>

لایه ی پنچم fragment_home.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="androidhive.info.materialdesign.activity.HomeFragment">


    <TextView
android:id="@+id/label"
android:layout_alignParentTop="true"
android:layout_marginTop="100dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="45dp"
android:text="HOME"
android:textStyle="bold"/>

    <TextView
android:layout_below="@id/label"
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="Edit fragment_home.xml to change the appearance" />

</RelativeLayout>

لایه ی ششم fragment_friends.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="androidhive.info.materialdesign.activity.HomeFragment">


    <TextView
android:id="@+id/label"
android:layout_alignParentTop="true"
android:layout_marginTop="100dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="45dp"
android:text="FRIENDS"
android:textStyle="bold"/>

    <TextView
android:layout_below="@id/label"
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="Edit fragment_home.xml to change the appearance" />

</RelativeLayout>

لایه ی activity_main رو مثل من در بیارید:

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">


    <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

        <LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

            <include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
            <View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/toolbar"
android:background="@drawable/toolbar_elevation" />
        </LinearLayout>

        <FrameLayout
android:id="@+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />


    </LinearLayout>


    <fragment
android:id="@+id/fragment_navigation_drawer"
android:name="yazadany.saeid.mytest.FragmentDrawer"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer" />

</android.support.v4.widget.DrawerLayout>

خب تموم شد ساخت لایه هامون حالا میریم سمت کد زدن :)

نظرات

saeidhic 11 سال پیش

در این مرحله یک کلاس به نام NavDrewerItem ایجاد میکنیم 

روی پکیج برنامه کلیک راست کنید بعد منوی new و بعد java class رو بزنید و یک کلاس به همون نامی که گفتم میسازیم

کد های زیرو داخلش میزنیم:

 public class NavDrawerItem {
    private boolean showNotify;
private String title;


public NavDrawerItem() {

    }

    public NavDrawerItem(boolean showNotify, String title) {
        this.showNotify = showNotify;
this.title = title;
}

    public boolean isShowNotify() {
        return showNotify;
}

    public void setShowNotify(boolean showNotify) {
        this.showNotify = showNotify;
}

    public String getTitle() {
        return title;
}

    public void setTitle(String title) {
        this.title = title;
}
}

نظرات

saeidhic 11 سال پیش

 کلاس های FragmentMessage  و  FragmentHome  و  FragmentFriends رو  هم میسازیم 

اینم کد هاش :

 

 

 public class HomeFragment extends Fragment {

    public HomeFragment() {
        // Required empty public constructor
}

    @Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

}

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_home, container, false);


// Inflate the layout for this fragment
return rootView;
}

    @Override
public void onAttach(Activity activity) {
        super.onAttach(activity);
}

    @Override
public void onDetach() {
        super.onDetach();
}
}

 

 public class MessagesFragment extends Fragment {

    public MessagesFragment() {
        // Required empty public constructor
}

    @Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

}

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_messages, container, false);


// Inflate the layout for this fragment
return rootView;
}

    @Override
public void onAttach(Activity activity) {
        super.onAttach(activity);
}

    @Override
public void onDetach() {
        super.onDetach();
}
}

نظرات

saeidhic 11 سال پیش

کلاس NavigationDrawerAdapter رو میسازیم:

 public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.MyViewHolder> {
    List<NavDrawerItem> data = Collections.emptyList();
private LayoutInflater inflater;
private Context context;

public NavigationDrawerAdapter(Context context, List<NavDrawerItem> data) {
        this.context = context;
inflater = LayoutInflater.from(context);
this.data = data;
}

    public void delete(int position) {
        data.remove(position);
notifyItemRemoved(position);
}

    @Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.nav_drawer_row, parent, false);
MyViewHolder holder = new MyViewHolder(view);
return holder;
}

    @Override
public void onBindViewHolder(MyViewHolder holder, int position) {
        NavDrawerItem current = data.get(position);
holder.title.setText(current.getTitle());
}

    @Override
public int getItemCount() {
        return data.size();
}

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView title;

public MyViewHolder(View itemView) {
            super(itemView);
title = (TextView) itemView.findViewById(R.id.title);
}
    }
}

نظرات

saeidhic 11 سال پیش

کلاس FragmentDrawer رو میسازیم :

 public class FragmentDrawer extends Fragment {

    private static String TAG = FragmentDrawer.class.getSimpleName();

private RecyclerView recyclerView;
private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout;
private NavigationDrawerAdapter adapter;
private View containerView;
private static String[] titles = null;
private FragmentDrawerListener drawerListener;

public FragmentDrawer() {

    }

    public void setDrawerListener(FragmentDrawerListener listener) {
        this.drawerListener = listener;
}

    public static List<NavDrawerItem> getData() {
        List<NavDrawerItem> data = new ArrayList<>();


// preparing navigation drawer items
for (int i = 0; i < titles.length; i++) {
            NavDrawerItem navItem = new NavDrawerItem();
navItem.setTitle(titles[i]);
data.add(navItem);
}
        return data;
}

    @Override
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

// drawer labels
titles = getActivity().getResources().getStringArray(R.array.nav_drawer_labels);
}

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
        // Inflating view layout
View layout = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
recyclerView = (RecyclerView) layout.findViewById(R.id.drawerList);

adapter = new NavigationDrawerAdapter(getActivity(), getData());
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity(), recyclerView, new ClickListener() {
            @Override
public void onClick(View view, int position) {
                drawerListener.onDrawerItemSelected(view, position);
mDrawerLayout.closeDrawer(containerView);
}

            @Override
public void onLongClick(View view, int position) {

            }
        }));

return layout;
}


    public void setUp(int fragmentId, DrawerLayout drawerLayout, final Toolbar toolbar) {
        containerView = getActivity().findViewById(fragmentId);
mDrawerLayout = drawerLayout;
mDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {
            @Override
public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
getActivity().invalidateOptionsMenu();
}

            @Override
public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
getActivity().invalidateOptionsMenu();
}

            @Override
public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, slideOffset);
//                toolbar.setAlpha(1 - slideOffset / 2);
}
        };

mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerLayout.post(new Runnable() {
            @Override
public void run() {
                mDrawerToggle.syncState();
}
        });

}

    public static interface ClickListener {
        public void onClick(View view, int position);

public void onLongClick(View view, int position);
}

    static class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {

        private GestureDetector gestureDetector;
private ClickListener clickListener;

public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final ClickListener clickListener) {
            this.clickListener = clickListener;
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
                @Override
public boolean onSingleTapUp(MotionEvent e) {
                    return true;
}

                @Override
public void onLongPress(MotionEvent e) {
                    View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
if (child != null && clickListener != null) {
                        clickListener.onLongClick(child, recyclerView.getChildPosition(child));
}
                }
            });
}

        @Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {

            View child = rv.findChildViewUnder(e.getX(), e.getY());
if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
                clickListener.onClick(child, rv.getChildPosition(child));
}
            return false;
}

        @Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
        }

        @Override
public void onRequestDisallowInterceptTouchEvent(boolean b) {

        }
    }

    public interface FragmentDrawerListener {
        public void onDrawerItemSelected(View view, int position);
}
}

توجه کنید دوستان این قسمت رو خودتون ادیت کنید و سبک ترش کنید به نظرم بهتره

نظرات

saeidhic 11 سال پیش

کلاس MainActivity رو هم کداش رو اینجوری بزنید :

 public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener {

    private static String TAG = MainActivity.class.getSimpleName();

    private Toolbar mToolbar;
    private FragmentDrawer drawerFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mToolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayShowHomeEnabled(true);

        drawerFragment = (FragmentDrawer)
                getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
        drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
        drawerFragment.setDrawerListener(this);

        // display the first navigation drawer view on app launch
        displayView(0);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.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();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        if(id == R.id.action_search){
            Toast.makeText(getApplicationContext(), "Search action is selected!", Toast.LENGTH_SHORT).show();
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onDrawerItemSelected(View view, int position) {
        displayView(position);
    }

    private void displayView(int position) {
        Fragment fragment = null;
        String title = getString(R.string.app_name);
        switch (position) {
            case 0:
                fragment = new HomeFragment();
                title = getString(R.string.title_home);
                break;
            case 1:
                fragment = new FriendsFragment();
                title = getString(R.string.title_friends);
                break;
            case 2:
                fragment = new MessagesFragment();
                title = getString(R.string.title_messages);
                break;
            default:
                break;
        }

        if (fragment != null) {
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.container_body, fragment);
            fragmentTransaction.commit();

            // set the toolbar title
            getSupportActionBar().setTitle(title);
        }
    }
}

نظرات

mahdi2565 11 سال پیش
آقا سعید شما هم در اندروید استادیو مشکل هنگ کردن مدام و دیر دیباگ شدن برنامه رو دارید ؟؟؟؟ اخه سرعتش خیلی داره ازارم میده !!!!
saeidhic 11 سال پیش
قبلا این مشکل رو داشتم چون سیستمم خیلی کند بود اما الان با لپتاپ جدیدی که گرفتم مشکل سرعت ندارم ولی درکل Android Studio خیلی لفت میده تا بخواد یک خروجی بده اما Eclipse فورا خروجی میده من خودم زیاد با Android Studio حال نمیکنم اما دیگه باید کم کم محاجرت کنیم چون که گوگل کلا پشتیبانیش رو قطع کرد :(
saeidhic 11 سال پیش
فکر کنم اگر شما هگزم اینتل رو نصب کنید مشکلتون برطرف بشه البته باید پردازندتون از نوع hasswell باشه حالا یا core i3 یا core i5 یا 7 سرعت sign کردن apk ها در کل خروجی دادن میره بالا
mahdi2565 11 سال پیش
ه ... cup من دو هسته ای 3 گیگاهرتز هست !!!!!!!!!!!!!!!! پس خداروشکر اگه سیستمه کامپیوترو ببرم بالا درست میشه !!!!
saeidhic 11 سال پیش
100% دوست عزیز :)
saeidhic 11 سال پیش

دوستان یه سری از مراحل آموزش طی ادیت کردن به مشکل برخوردن مجبورم دوباره براتون بذارمشون

از مرحله ای که گفتم دایرکتوری values-v21 رو میسازیم براتون میذارم

خب وقتی که دایرکتوری values-v21 رو ساختید روی دایرکتوری values کلیک راست کنید و Android Resource file رو کلیک کنید طبق عکسی که براتون بالا گذاشتم دوباره براتون میذارم که گیج نشید

یک استایل ایجاد میشه روی پوشه ی استایل کلیک کنید و styles.xml (v21 رو انتخاب کنید کد های زیر رو توش بزنید

 <?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="MyMaterialTheme" parent="MyMaterialTheme.Base">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>

</resources>

نظرات

saeidhic 11 سال پیش

بعدش گفتم که  Elevation در اندروید 5 فقط جواب میده واسه این که رو تمامیه ورژن ها جواب بده ما از یک customView استفاده میکنیم

روی فایل res کلیک راست کنید پوشه ی drawable و بسازید و روی drawable کلیک راست کنید Android drawable file رو کلیک کنید

داخلش این کد هارو بزنید : اسم فایلشم بذارید toolbar_elevation.xml

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<gradient
android:angle="90"
android:endColor="#88444444"
android:startColor="@android:color/transparent" />

</shape>

نظرات

saeidhic 11 سال پیش

فایل activity_main.xml رو اینجوری کد هاشو توش وارد کنید : بعدش تا همینجا برنامه رو اجرا کنید :
دقت کنید که در مانیفست تم رو تغییر ندید فعلا تا بگم چیکار کنید:

بعد از اجرا اگه برنامه خطایی نداشت به ادامه ی آموزش ها برید و این فایل activity_main رو مطابق با آموزش ها باز ادیت کنید

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="saeid.test.mystartup5.MainActivity" xmlns:app1="http://schemas.android.com/apk/res/saeid.test.mystartup5">

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
app1:navigationIcon="@drawable/ic_launcher"
local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/toolbar"
android:background="@drawable/toolbar_shadow" />

</RelativeLayout>

نظرات

saeidhic 11 سال پیش

در آخرین مرحله از آموزش ها در مانیفست بعد از اینکه  همه ی اون کارایی که گفتم رو کریدید تم رو تغییر بدید و بذارید روی :

MyMaterialTheme

تمام!

آموزش اکلیپس هم براتون میذارم ولی بعد از استراحت :)

نظرات

mahdi2565 11 سال پیش
من الان هنگه اینم که شما چجوری اموزش متریال برای اکلیپس رو پیدا کردین !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
saeidhic 11 سال پیش
تا دقایقی دیگه براتون میذارم آموزش رو :)
saeidhic 11 سال پیش

خب من باز اومدم

ببینید تنها فرق اکلیپس با Android Studio تو RecyclerView اینه که  خب Android Studio این لایبراری رو میشناسه اما اکلیپس نه

یعنی اگه خودتم بکشی و کتابخونش رو از طریق eclipse ایمپورت کنی بازم نمیشه!

خب حالا باید چیکار کرد!

بهتون یاد میدم

من خودم از جایی آموزش ندیدم اما این کلک رو سوار کردم و جواب داد خیلی ساده :)

نظرات


پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .