<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>جاوا &#8211; طراحی سایت، ربات تلگرام و راهکارهای هوش مصنوعی | پشتیبانی 24 ساعته | مشاوره رایگان | Piero.ir</title>
	<atom:link href="https://piero.ir/tag/%D8%AC%D8%A7%D9%88%D8%A7/feed/" rel="self" type="application/rss+xml" />
	<link>https://piero.ir</link>
	<description>Piero.ir ارائه‌دهنده طراحی سایت حرفه‌ای، ساخت ربات تلگرام، اتوماسیون n8n، هوش مصنوعی، یادگیری ماشین و راه‌اندازی استارتاپ‌های نوآورانه. راهکارهای اختصاصی و مشتری‌محور برای رشد کسب‌وکار شما.</description>
	<lastBuildDate>Fri, 26 Sep 2025 01:57:03 +0000</lastBuildDate>
	<language>fa-IR</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>

<image>
	<url>https://piero.ir/wp-content/uploads/2025/08/logopiero-100x100.png</url>
	<title>جاوا &#8211; طراحی سایت، ربات تلگرام و راهکارهای هوش مصنوعی | پشتیبانی 24 ساعته | مشاوره رایگان | Piero.ir</title>
	<link>https://piero.ir</link>
	<width>32</width>
	<height>32</height>
</image> 
        <wp_options>
            <wp_option>
                <name>
                    shopengine_activated_templates                </name>
                <val>
                    a:0:{}                </val>
            </wp_option>
        </wp_options>
        	<item>
		<title>آموزش ساخت تب در اندروید</title>
		<link>https://piero.ir/tabhost/</link>
					<comments>https://piero.ir/tabhost/#respond</comments>
		
		<dc:creator><![CDATA[پیروز جنابی]]></dc:creator>
		<pubDate>Thu, 27 Oct 2016 19:11:56 +0000</pubDate>
				<category><![CDATA[آموزش اندروید استدیو]]></category>
		<category><![CDATA[آموزش رایگان]]></category>
		<category><![CDATA[افزونه های اندروید استدیو]]></category>
		<category><![CDATA[آموزش برنامه نویسی]]></category>
		<category><![CDATA[اندروید استادیو]]></category>
		<category><![CDATA[برنامه نویسی]]></category>
		<category><![CDATA[جاوا]]></category>
		<guid isPermaLink="false">http://www.piero.ir/?p=488</guid>

					<description><![CDATA[آموزش ساخت تب در اندروید یکی از ویژگی های برنامه های حرفه ای در اندروید منویی در حالت تب است که می توان با آن ار صفحات بصورت خیلی بهینه استفاده کرد. &#160; برای ساخت تب در اندروید استادیو  از  tabhost استفاده می شود. که با کشیدن و رها کردن آن در صفحه layout ساخته [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>آموزش ساخت تب در اندروید</h1>
<p>یکی از ویژگی های برنامه های حرفه ای در اندروید منویی در حالت تب است که می توان با آن ار صفحات بصورت خیلی بهینه استفاده کرد.</p>
<figure id="attachment_489" aria-describedby="caption-attachment-489" style="width: 280px" class="wp-caption aligncenter"><img decoding="async" class="wp-image-489 size-full" src="http://www.piero.ir/wp-content/uploads/2016/10/tabs.jpg" alt="استفاده از  tabhost" width="280" height="157" /><figcaption id="caption-attachment-489" class="wp-caption-text">استفاده از tabhost</figcaption></figure>
<figure id="attachment_493" aria-describedby="caption-attachment-493" style="width: 168px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" class="wp-image-493 size-medium" src="http://www.piero.ir/wp-content/uploads/2016/10/screen1-168x300.jpg" alt="استفاده از  tabhost" width="168" height="300" /><figcaption id="caption-attachment-493" class="wp-caption-text">استفاده از tabhost</figcaption></figure>
<p>&nbsp;</p>
<h3>برای ساخت تب در اندروید استادیو  از  tabhost استفاده می شود.</h3>
<p>که با کشیدن و رها کردن آن در صفحه layout ساخته می شود و ترکیب زیر را ذارد.</p>
<pre class="lang:default decode:true">    &lt;TabHost
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tabHost"
        android:layout_gravity="center_horizontal"
        android:layout_weight="0.03"&gt;

        &lt;LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"&gt;

            &lt;TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"&gt;&lt;/TabWidget&gt;

            &lt;FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"&gt;

                &lt;LinearLayout
                    android:id="@+id/linearLayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"&gt;
                    &lt;TextView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:text="@string/formul"
                        android:background="@color/menu4"
                        /&gt;

                &lt;/LinearLayout&gt;

                &lt;LinearLayout
                    android:id="@+id/linearLayout2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"&gt;
                    &lt;TextView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:text="@string/aboutapp"
                        android:background="@color/menu4"
                        /&gt;
                &lt;/LinearLayout&gt;

                &lt;LinearLayout
                    android:id="@+id/linearLayout3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"&gt;

                    &lt;TextView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:text="@string/best"
                        android:background="@color/menu4"
                        /&gt;
                &lt;/LinearLayout&gt;
            &lt;/FrameLayout&gt;
        &lt;/LinearLayout&gt;
    &lt;/TabHost&gt;</pre>
<p>&nbsp;</p>
<p>توجه داشته باشید شما با linearlayout کار دارید و اجزای صفحات را درون آن می گزارید.</p>
<p>و حالا به سراغ کد آن می رویم که بسیار راحت است.</p>
<pre class="lang:default decode:true ">import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;

/**
 * Created by piero on 10/27/16.
 */
public class formul1 extends Activity {

TabHost
    tabHost;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.formule1);

        //معرفی تب هاست
        tabHost = (TabHost) findViewById(R.id.tabHost);
        tabHost.setup();


//افزودن تب ۱
        TabHost.TabSpec spec1=tabHost.newTabSpec("TAB 1");
        spec1.setContent(R.id.linearLayout);
        spec1.setIndicator("Appinapps");

//افزودن تب ۲

        TabHost.TabSpec spec2=tabHost.newTabSpec("TAB 2");
        spec2.setContent(R.id.linearLayout2);
        spec2.setIndicator("google");

//افزودن تب ۳
        TabHost.TabSpec spec3=tabHost.newTabSpec("TAB 3");
        spec3.setContent(R.id.linearLayout3);
        spec3.setIndicator("piero");

//        افزودن تب ها
        tabHost.addTab(spec1);
        tabHost.addTab(spec2);
        tabHost.addTab(spec3);

    }

}
</pre>
<p>&nbsp;</p>
<p>واکنون برنامه شما آمادست.</p>
<p>&nbsp;</p>
<h2>اسکرول شدن محتوا در تب هاست</h2>
<p>به منظور اسکرول شدن کافی است از Scrollview در Linearlayout استفاده نمایید به تزتیب زیر.</p>
<pre class="lang:default decode:true ">                &lt;LinearLayout
                    android:id="@+id/linearLayout3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"&gt;

                    &lt;ScrollView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"&gt;
                        &lt;TextView
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:text="@string/formul"
                            android:background="@color/menu4"
                            /&gt;
                    &lt;/ScrollView&gt;
                &lt;/LinearLayout&gt;</pre>
<p>&nbsp;</p>
<p>در واقع کد شما می شود :</p>
<pre class="lang:default decode:true">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/listbackground"
    android:weightSum="1"
    android:layoutDirection="rtl"
    &gt;
    &lt;RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@color/menu6"

        &gt;
    &lt;TextView
        android:textStyle="bold"
        android:id="@+id/emkanattitle"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/formulmenu1"
        android:gravity="center"
        android:textColor="@color/menutext1"
        android:textSize="25dp"
        android:drawableLeft="@drawable/icon7"
        android:paddingLeft="10dp"
        /&gt;


    &lt;/RelativeLayout&gt;

    &lt;TabHost
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tabHost"
        android:layout_gravity="center_horizontal"
        android:layout_weight="0.03"&gt;

        &lt;LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"&gt;

            &lt;TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"&gt;&lt;/TabWidget&gt;

            &lt;FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"&gt;

                &lt;LinearLayout
                    android:id="@+id/linearLayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"&gt;
                    &lt;ScrollView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"&gt;
                        &lt;TextView
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:text="@string/formul"
                            android:background="@color/menu4"
                            /&gt;
                    &lt;/ScrollView&gt;


                &lt;/LinearLayout&gt;

                &lt;LinearLayout
                    android:id="@+id/linearLayout2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"&gt;
                    &lt;ScrollView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"&gt;
                        &lt;TextView
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:text="@string/formul"
                            android:background="@color/menu4"
                            /&gt;
                    &lt;/ScrollView&gt;
                &lt;/LinearLayout&gt;

                &lt;LinearLayout
                    android:id="@+id/linearLayout3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"&gt;

                    &lt;ScrollView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"&gt;
                        &lt;TextView
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:text="@string/formul"
                            android:background="@color/menu4"
                            /&gt;
                    &lt;/ScrollView&gt;
                &lt;/LinearLayout&gt;
             &lt;/FrameLayout&gt;
        &lt;/LinearLayout&gt;
    &lt;/TabHost&gt;


&lt;/LinearLayout&gt;</pre>
<p>&nbsp;</p>
<h2>حساس شدن به تاچ در آموزش ساخت تب در اندروید</h2>
<p>با این کار ساده جلوه بسیار زیادی به برنامه تان می دهید . کاربر شما با عملیات swip می تواند بین تبها انتقال پیدا کند به طور عامیانه با دست کشیدن رو صفحه تبها عوض می شود.</p>
<p>برای این منظور فقط کافی است کد زیر را اضافه کنید.</p>
<pre class="lang:default decode:true ">//    تغییر در هنگامی که تاچی اتفاق میفتد
    @Override
    public boolean onTouchEvent(MotionEvent touchevent) {
        switch (touchevent.getAction()) {
            // when user first touches the screen to swap
            case MotionEvent.ACTION_DOWN: {
                lastX = touchevent.getX();
//                دریافت آخرین جایگاه تاچ
                break;
            }
            case MotionEvent.ACTION_UP: {
                float currentX = touchevent.getX();

                // if left to right swipe on screen
                if (lastX &lt; currentX) {

                    switchTabs(false);
                }

                // if right to left swipe on screen
                if (lastX &gt; currentX) {
                    switchTabs(true);
                }

                break;
            }
        }
        return false;
    }
//تابع انتقال بین تبها
    public void switchTabs(boolean direction) {
        if (direction) // true = move left
        {
            if (tabHost.getCurrentTab() == 0)
                tabHost.setCurrentTab(tabHost.getTabWidget().getTabCount() - 1);
            else
                tabHost.setCurrentTab(tabHost.getCurrentTab() - 1);
        } else
        // move right
        {
            if (tabHost.getCurrentTab() != (tabHost.getTabWidget()
                    .getTabCount() - 1))
                tabHost.setCurrentTab(tabHost.getCurrentTab() + 1);
            else
                tabHost.setCurrentTab(0);
        }
    }</pre>
<p>&nbsp;</p>
<h2>و در نهایت :</h2>
<pre class="lang:default decode:true">import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.TabHost;

/**
 * Created by piero on 10/27/16.
 */
public class formul1 extends Activity {

TabHost tabHost;
    float lastX;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.formule1);

        //معرفی تب هاست
        tabHost = (TabHost) findViewById(R.id.tabHost);
        tabHost.setup();


//افزودن تب ۱
        TabHost.TabSpec spec1=tabHost.newTabSpec("TAB 1");
        spec1.setContent(R.id.linearLayout);
        spec1.setIndicator("Appinapps");

//افزودن تب ۲

        TabHost.TabSpec spec2=tabHost.newTabSpec("TAB 2");
        spec2.setContent(R.id.linearLayout2);
        spec2.setIndicator("google");

//افزودن تب ۳
        TabHost.TabSpec spec3=tabHost.newTabSpec("TAB 3");
        spec3.setContent(R.id.linearLayout3);
        spec3.setIndicator("piero");

//        افزودن تب ها
        tabHost.addTab(spec1);
        tabHost.addTab(spec2);
        tabHost.addTab(spec3);

    }

//    تغییر در هنگامی که تاچی اتفاق میفتد
    @Override
    public boolean onTouchEvent(MotionEvent touchevent) {
        switch (touchevent.getAction()) {
            // when user first touches the screen to swap
            case MotionEvent.ACTION_DOWN: {
                lastX = touchevent.getX();
//                دریافت آخرین جایگاه تاچ
                break;
            }
            case MotionEvent.ACTION_UP: {
                float currentX = touchevent.getX();

                // if left to right swipe on screen
                if (lastX &lt; currentX) {

                    switchTabs(false);
                }

                // if right to left swipe on screen
                if (lastX &gt; currentX) {
                    switchTabs(true);
                }

                break;
            }
        }
        return false;
    }
//تابع انتقال بین تبها
    public void switchTabs(boolean direction) {
        if (direction) // true = move left
        {
            if (tabHost.getCurrentTab() == 0)
                tabHost.setCurrentTab(tabHost.getTabWidget().getTabCount() - 1);
            else
                tabHost.setCurrentTab(tabHost.getCurrentTab() - 1);
        } else
        // move right
        {
            if (tabHost.getCurrentTab() != (tabHost.getTabWidget()
                    .getTabCount() - 1))
                tabHost.setCurrentTab(tabHost.getCurrentTab() + 1);
            else
                tabHost.setCurrentTab(0);
        }
    }
}
</pre>
<p>آموزش ساخت تب در اندروید</p>

    <div class="xs_social_share_widget xs_share_url after_content 		main_content  wslu-style-1 wslu-share-box-shaped wslu-fill-colored wslu-none wslu-share-horizontal wslu-theme-font-no wslu-main_content">

		
        <ul>
			        </ul>
    </div> 
]]></content:encoded>
					
					<wfw:commentRss>https://piero.ir/tabhost/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>کد پرسش خروج برای اندروید</title>
		<link>https://piero.ir/%da%a9%d8%af-%d9%be%d8%b1%d8%b3%d8%b4-%d8%ae%d8%b1%d9%88%d8%ac-%d8%a8%d8%b1%d8%a7%db%8c-%d8%a7%d9%86%d8%af%d8%b1%d9%88%db%8c%d8%af/</link>
					<comments>https://piero.ir/%da%a9%d8%af-%d9%be%d8%b1%d8%b3%d8%b4-%d8%ae%d8%b1%d9%88%d8%ac-%d8%a8%d8%b1%d8%a7%db%8c-%d8%a7%d9%86%d8%af%d8%b1%d9%88%db%8c%d8%af/#respond</comments>
		
		<dc:creator><![CDATA[پیروز جنابی]]></dc:creator>
		<pubDate>Wed, 19 Oct 2016 15:01:03 +0000</pubDate>
				<category><![CDATA[آموزش اندروید استدیو]]></category>
		<category><![CDATA[اسکریپت]]></category>
		<category><![CDATA[اندروید]]></category>
		<category><![CDATA[اندروید استادیو]]></category>
		<category><![CDATA[برنامه نویسی]]></category>
		<category><![CDATA[جاوا]]></category>
		<guid isPermaLink="false">http://www.piero.ir/?p=471</guid>

					<description><![CDATA[کد پرسش خروج برای اندروید حتما برایتان پیش آمده در اندروید استادیو مایل باشید وقتی دکمه بازگشت خورده شود از کاربر بپرسد که آیا می خواهید خارج شوید یا نه؟ این کار معمولا در برنامه های حرفه ای انجام می شود و در صفحه اصلی (main) قرار می گیرد و از خروج اشتباهی جلوگیری می [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong>کد پرسش خروج برای اندروید</strong></p>
<p>حتما برایتان پیش آمده در اندروید استادیو مایل باشید وقتی دکمه بازگشت خورده شود از کاربر بپرسد که آیا می خواهید خارج شوید یا نه؟</p>
<p>این کار معمولا در برنامه های حرفه ای انجام می شود و در صفحه اصلی (main) قرار می گیرد و از خروج اشتباهی جلوگیری می کند.</p>
<pre class="lang:java decode:true">//www.piero.ir @ pirooz jenabi
@Override
    public void onBackPressed() {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setTitle("آیا تمایل به خروج دارید?");
        alertDialogBuilder
                .setMessage("آیا تمایل به خروج دارید?")
                .setCancelable(false)
                .setPositiveButton("بله",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                moveTaskToBack(true);
                                android.os.Process.killProcess(android.os.Process.myPid());
                                System.exit(1);
                            }
                        })

                .setNegativeButton("خیر", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                        dialog.cancel();
                    }
                });

        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }</pre>
<p>&nbsp;</p>
<h2>توضیح برنامه کد پرسش خروج برای اندروید :</h2>
<ul>
<li><span style="font-size: 14pt;">این تکه کد هنگامی اجرا می شود که عملیات onBackPressed() انجام شود(دکمه بازگشت )</span></li>
<li><span style="font-size: 14pt;">ابتدا دیالوگی را ساخته و هدر را قرار داده و بعد دو دکمه در آن تعبیه می کند و بعد برای رویداد کلیک هرکدام کد مخصوص آن را می نویسد.</span></li>
<li><span style="font-size: 14pt;">توجه داشته باشید شما می توانید آن را برای دکمه خروج هم تعبیه کنید فقط کافی است کد مورد نظر را درون تابع قرار دهید و بعد آن را صدا بزنید.</span></li>
<li><span style="font-size: 14pt;"> بهتر است متنهای مورد نظر را در فایل نوشته (string.xml) قرار دهید و بعد آنرا صدا بزنید.</span></li>
</ul>
<p>&nbsp;</p>
<p><strong>امیدواریم این تکه کد نیاز شما را بر آورده کند .</strong></p>

    <div class="xs_social_share_widget xs_share_url after_content 		main_content  wslu-style-1 wslu-share-box-shaped wslu-fill-colored wslu-none wslu-share-horizontal wslu-theme-font-no wslu-main_content">

		
        <ul>
			        </ul>
    </div> 
]]></content:encoded>
					
					<wfw:commentRss>https://piero.ir/%da%a9%d8%af-%d9%be%d8%b1%d8%b3%d8%b4-%d8%ae%d8%b1%d9%88%d8%ac-%d8%a8%d8%b1%d8%a7%db%8c-%d8%a7%d9%86%d8%af%d8%b1%d9%88%db%8c%d8%af/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
