¾È±Ô °øºÎ¹æ

Android > ActionBar - Ä¿½ºÅÒ ¾×¼Ç¹Ù ¸¸µé±â

µî·ÏÀÏ : 2017-07-05 18:55 Á¶È¸¼ö : 53,296

À̹ø °­ÀÇ´Â Ä¿½ºÅÒ ¾×¼Ç¹Ù¸¦ ¸¸µå´Â ¹æ¹ýÀ» ¾Ë·Áµå¸®µµ·Ï ÇÏ°Ú½À´Ï´Ù.




layout Æú´õÀÇ [layout_actionbar.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="60dp"> 
		<ImageButton 
			android:layout_width="30dp" 
			android:layout_height="30dp" 
			android:layout_centerVertical="true" 
			android:layout_marginLeft="10dp" 
			android:background="@drawable/btn_back"/> 

		<ImageView 
			android:layout_width="130dp" 
			android:layout_height="35dp" 
			android:layout_centerInParent="true" 
			android:background="@drawable/choayo"/> 
	   
		<ImageButton 
			android:layout_width="30dp" 
			android:layout_height="30dp" 
			android:layout_alignParentRight="true" 
			android:layout_centerVertical="true" 
			android:layout_marginRight="10dp" 
			android:background="@drawable/btn_userinfo"/> 
	</RelativeLayout> 
	


¿øÇϽô µðÀÚÀÎÀ¸·Î ¸¸µå½Ã¸é µË´Ï´Ù.

MainActivity.java ÆÄÀÏ ÄÚµù ³»¿ëÀÔ´Ï´Ù.
		setContentView(R.layout.layout_noti);

		actionBar = getActionBar();
		actionBar.setNavigationMode( ActionBar.NAVIGATION_MODE_TABS );

		// Custom Actionbar¸¦ »ç¿ëÇϱâ À§ÇØ CustomEnabledÀ» true ½ÃÅ°°í ÇÊ¿ä ¾ø´Â °ÍÀº false ½ÃŲ´Ù 
		actionBar.setDisplayShowCustomEnabled(true); 
		actionBar.setDisplayHomeAsUpEnabled(false);			//¾×¼Ç¹Ù ¾ÆÀÌÄÜÀ» ¾÷ ³×ºñ°ÔÀÌ¼Ç ÇüÅ·Πǥ½ÃÇÕ´Ï´Ù.
		actionBar.setDisplayShowTitleEnabled(false);		//¾×¼Ç¹Ù¿¡ Ç¥½ÃµÇ´Â Á¦¸ñÀÇ Ç¥½ÃÀ¯¹«¸¦ ¼³Á¤ÇÕ´Ï´Ù.
		actionBar.setDisplayShowHomeEnabled(false);			//Ȩ ¾ÆÀÌÄÜÀ» ¼û±èó¸®ÇÕ´Ï´Ù.

		//layoutÀ» °¡Áö°í ¿Í¼­ actionbar¿¡ Æ÷ÆÃÀ» ½Ãŵ´Ï´Ù.
		View mCustomView = LayoutInflater.from(this).inflate(R.layout.layout_actionbar, null); 
		actionBar.setCustomView(mCustomView); 


		// ¾×¼Ç¹Ù¿¡ ¹é±×¶ó¿îµå »ö»óÀ» ¾Æ·¡Ã³·³ ÀÔÈú ¼ö ÀÖ½À´Ï´Ù. 
        //actionBar.setBackgroundDrawable(new ColorDrawable(Color.argb(255,255,255,255)));
        

		// ¾×¼Ç¹Ù¿¡ ¹é±×¶ó¿îµå À̹ÌÁö¸¦ ¾Æ·¡Ã³·³ ÀÔÈú ¼ö ÀÖ½À´Ï´Ù. (drawable Æú´õ¿¡ img_action_background.png ÆÄÀÏÀÌ ÀÖ¾î¾ß °ÚÁÒ?)
		actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.img_action_background)); 

		showNotiPannel = false;
		Button btn = (Button) findViewById(R.id.button1);

		btn.setOnClickListener(
			new Button.OnClickListener() {
				@Override
				public void onClick(View v) {
					 if ( showNotiPannel ){
							notiPannel.setVisibility(View.GONE);
							showNotiPannel = false;
						}else{
							notiPannel.setVisibility(View.VISIBLE);
							showNotiPannel = true;
						}
				}
			}
		);


À§ ¼Ò½º ÁÖ¼®À» º¸¸é ¾Ë°ÚÁö¸¸ layout_actionbar.xml ÆÄÀÏÀÇ layoutÀ»  mCustomView ·Î ÂüÁ¶½Ãŵ´Ï´Ù.

±×·±ÈÄ actionbarÀÇ setCustomView() ¸Þ¼­µå¿¡ Æ÷Æà ½ÃÅ°¸é ³¡ÀÌ ³³´Ï´Ù.

¾Æ·¡ ¼Ò½º 󷳿ä. ¹é±×¶ó¿îµåÀ̹ÌÁö ó¸®ÇÏ´Â ¹æ¹ýµµ ÀÖÀ¸´Ï, Âü°í ÇϽñ⠹ٶø´Ï´Ù.
 
	View mCustomView = LayoutInflater.from(this).inflate(R.layout.layout_actionbar, null); 
	actionBar.setCustomView(mCustomView); 


	// ¾×¼Ç¹Ù¿¡ ¹é±×¶ó¿îµå À̹ÌÁö¸¦ ¾Æ·¡Ã³·³ ÀÔÈú ¼ö ÀÖ½À´Ï´Ù. (drawable Æú´õ¿¡ img_action_background.png ÆÄÀÏÀÌ ÀÖ¾î¾ß °ÚÁÒ?)
	actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.img_action_background)); 

	// ¾×¼Ç¹Ù¿¡ ¹é±×¶ó¿îµå »ö»óÀ» ¾Æ·¡Ã³·³ ÀÔÈú ¼ö ÀÖ½À´Ï´Ù. 
	actionBar.setBackgroundDrawable(new ColorDrawable(Color.argb(255,255,255,255)));
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.