วันจันทร์ที่ 15 กันยายน พ.ศ. 2557

การ Update Version ของแอพที่เคยส่งขึ้น Play Store ไปแล้ว

การ Update Version ของแอพที่เคยส่งขึ้น Play Store ไปแล้ว

- ต้องใช้ package เดิม เหมือนตัวก่อนที่เคยส่งขึ้นไป
- ต้องใช้ Key store อันเดิม
- ไปที่ build.gradle   แล้วเปลี่ยน
        versionCode 1 เป็น 2 หรืออะไรก็ว่าไป
        versionName "1" เป็น "อะไรก็ว่าไป"


สร้าง Dialog ยืนยันการออกจากแอพ ตอน กดปุ่ม Back

สร้าง Dialog ตอน กดปุ่ม Back

ต้องสร้างในหน้าหลัก ที่ไม่ใช่ Fragment นะจ้ะ 


    public void onBackPressed() {
        Log.e("Back Press", "กดปุ่ม Back แล้ว");
        // กดปุ่ม Back แล้วจะให้โปรแกรมทำอะไรให้ใส่ในนี้
        final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
        dialog.setTitle("Exit");
        dialog.setIcon(R.drawable.ic_launcher);
        dialog.setCancelable(true);
        dialog.setMessage("Sure Exit ?");

        dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                                      finish();


            }   // Onclick Dialog Yes

        });

        dialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {


            }   //  Event
        });

        dialog.show();
    }

วันอาทิตย์ที่ 14 กันยายน พ.ศ. 2557

วันศุกร์ที่ 12 กันยายน พ.ศ. 2557

วันศุกร์ที่ 29 สิงหาคม พ.ศ. 2557

การเปลี่ยน theme app

   ไปที่ res->values->style.xml

1.   เพิ่มไปใน <resource>
 <style name="ชื่อสไตที่เมิงตั้งใหม่" parent="AppTheme">

        <item name="android:windowNoTitle">true</item>
        <item name="android:windowContentOverlay">@null</item>


    </style>
<resource>

2. ไปที่ androidmanifest.xml

หาแล้วแก้แค่เนี่ย
android:theme="@style/ชื่อสไตที่เมิงตั้งใหม่"

จบละฝัดด เบย

การใช้งาน ViewPagerIndicator


1.สร้าง MainActivity with Fragment

\\MainActivity//

import com.viewpagerindicator.PageIndicator;
import com.viewpagerindicator.TitlePageIndicator;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;

public class MainmenuActivity extends FragmentActivity {
  
    FragmentAdapter mAdapter;
    ViewPager mPager;
    PageIndicator mIndicator;
    int Number = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout."ชื่อ layout ของเรา");
      
        mAdapter = new FragmentAdapter(getSupportFragmentManager());
        mPager = (ViewPager)findViewById(R.id.pager);
        mPager.setAdapter(mAdapter);
                 เปลี่ยนเป็น สไตต่างๆเช่น
                  Title
                  //mIndicator = (TitlePageIndicator)findViewById(R.id.indicator);

                   Tab
        //mIndicator = (TabPageIndicator)findViewById(R.id.indicator);
                    เลือกเอาซักอย่าง

        mIndicator.setViewPager(mPager);
     
    }
  
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu. "ดูชื่อใน res->menu แล้วก็อบมาใส" , menu);
        return true;
    }
  
  
}

เออเร่อชั่งมั้น กดแก้เองเด๋วมันก็หาย
หน้า xml ของ MainActivity


\\Your Fragment Holder in the XML//
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">


//Title    <com.viewpagerindicator.TitlePageIndicator
         //Tab    <com.viewpagerindicator.TabPageIndicator  เลือกเอา
        android:id="@+id/indicator"
        android:padding="10dip"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:background="#000000"
        android:textColor="#2FB3E3"
        />
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        /> 
</LinearLayout>

จากนั้นก็ไปที่ res->values->style.xml  ถ้าใช้ Tab ใส่ลงไปใน AppTheme ด้วย 
ไม่งั้นแม่งสไตหายกุงงตั้งนานไอสัส
<item name="vpiTabPageIndicatorStyle">@style/Widget.TabPageIndicator</item>

2. สร้าง FragmentAdapter.java 

\\Fragment Adapter//

import com.viewpagerindicator.IconPagerAdapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class FragmentAdapter extends FragmentPagerAdapter implements IconPagerAdapter{
    public FragmentAdapter(FragmentManager fm) {
        super(fm);
        // TODO Auto-generated constructor stub
    }
    @Override
    public int getIconResId(int index) {
        // TODO Auto-generated method stub
        return 0;
    }
    @Override
    public Fragment getItem(int position)
    {
        // TODO Auto-generated method stub
        Fragment fragment = new BitFragment();
        switch(position){
        case 0:
            fragment = new BitFragment();
            break;
        case 1:
            fragment = new ByteFragment();
            break;
        case 2:
            fragment = new KiloByteFragment();
            break;
        case 3:
            fragment = new MegaByteFragment();
            break;
        }
        return fragment;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub

                 มีกี่ tab เมิงกะใส่ตรงนี้นะ
        return 4;
    }
  
    @Override
    public CharSequence getPageTitle(int position){
        String title = "";
        switch(position){
        case 0:
            title = "Bit";
            break;
        case 1:
            title = "Byte";
            break;
        case 2:
            title = "KiloByte";
            break;
        case 3:
            title = "MegaByte";
            break;
        }
        return title;
    }
}
 3.สร้าง Fragment (Activity ) class+xml หน้าต่างๆที่จะเรียกใช้

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class ชื่อไรก็ว่าไปFragment extends Fragment {
  
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        View rootview = inflater.inflate(R.layout.ชื่อเลเอ้าเปลี่ยนตามด้วย, null);
        
         //Calendar
         CaldroidFragment caldroidFragment;
        caldroidFragment = new CaldroidFragment();
        Bundle args = new Bundle();
        Calendar cal = Calendar.getInstance();
        args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1);
        args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR));
        caldroidFragment.setArguments(args);
        android.support.v4.app.FragmentTransaction t = getFragmentManager().beginTransaction();
        t.replace(R.id.calendar1, caldroidFragment);
        t.commit();


        //  About Clear Button
        Button btnMultipleClear = (Button) view.findViewById(R.id.btnMultipleClear);
        btnMultipleClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getActivity(), "Clear", Toast.LENGTH_SHORT).show();
            }
        });
      
      
        return rootview ;
      
    }
}
    xml กำหนดเองเลยอยากใส่ไรใส่ได้เลย



เดบิต By Mizzeeboy กุรักเมิงฝุดๆขอบใจมากๆ

วันอาทิตย์ที่ 24 สิงหาคม พ.ศ. 2557

Android Studio Add ViewPagerIndicator Library with Gradle

บาง library ใน Android Studio แอดแบบปกติไม่ได้ พอดีเจอมาอีกวิธีนึง ง่ายมากเลย
(กว่ากุจาหาเจอสาดเอ้ยยยย!!!)


1. เข้า build.gradle ของโปรเจค แล้ว ก็ใส่ตามรูปด้านขวาล่าง ***ต้องใส่ข้างบน jcenter()
        maven
                {
                    url "http://dl.bintray.com/populov/maven"
                }
jcenter()




2. เข้า build.gradle ของ module แล้วก็ใส่ตามรูปด้านขวาล่าง
       compile 'com.viewpagerindicator:library:2.4.1@aar'




แค่นี้ก็ใช้ได้แล้ววุ้ยยยยยย