?u anda üzerinde çal??t???m Projede kullanmak için android toolbarlar?na benzer bir custom tool bar yapmak istedik. A?a??da nas?l yap?labilece?ine dair bilgileri bulacaks?n?z.
öncelikle custom tool bar için bir xml olu?turuyorum. Ben navigation.xml olarak layout filelerinin aras?nda olu?turdum.
[code lang=”xml”]
android:layout_width="80dip"
android:text="Title 1"
android:textSize="10dip"
android:textStyle="bold"
android:textColor="@drawable/text_states"
android:clickable="true"
android:focusable="true"
android:background="@drawable/backgound_states"
android:drawableTop="@android:drawable/ic_menu_edit"
android:gravity="center"
android:layout_weight="1"/>
android:layout_width="80dip"
android:text="Title 2"
android:textSize="10dip"
android:textStyle="bold"
android:textColor="@drawable/text_states"
android:clickable="true"
android:focusable="true"
android:background="@drawable/backgound_states"
android:drawableTop="@android:drawable/ic_menu_zoom"
android:gravity="center"
android:layout_weight="1"/>
android:layout_width="80dip"
android:text="Title 3"
android:textSize="10dip"
android:textStyle="bold"
android:textColor="@drawable/text_states"
android:clickable="true"
android:focusable="true"
android:background="@drawable/backgound_states"
android:drawableTop="@android:drawable/ic_menu_add"
android:gravity="center"
android:layout_weight="1"/>
android:layout_width="80dip"
android:layout_height="70dip"
android:layout_weight="1"
android:background="@drawable/backgound_states"
android:clickable="true"
android:drawableTop="@android:drawable/ic_menu_help"
android:focusable="true"
android:gravity="center"
android:text="Title 4"
android:textColor="@drawable/text_states"
android:textSize="10dip"
android:textStyle="bold" />
[/code]
Daha sonra drawable klasörünün alt?na textcolor ve background ayarlar? için iki xml dosya daha olu?turuyorum.
1. text_states dosyas? .
[code lang=”xml”]
android:state_pressed="true"
android:color="@android:color/black" />
android:state_pressed="false"
android:color="@android:color/black" />
android:state_pressed="true"
android:color="@android:color/black" />
[/code]
BackGround içinse background_states adl? yine drawable klasörleri alt?nda bir dosya olu?turuyoruz.
[code lang=”xml”]
android:state_pressed="true"
android:drawable="@android:color/darker_gray" />
android:state_pressed="false"
android:drawable="@android:color/darker_gray" />
android:state_pressed="true"
android:drawable="@android:color/darker_gray" />
[/code]
s?ra geldi toolbar?m?z?n java class?n? olu?turmaya. Toolbar isimli bir java class olu?tural?m ve a?a??daki kodu yap??t?ral?m.
[code lang=”java”]
package com.hlmcorp;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Intent;
public class Toolbar extends LinearLayout {
public Toolbar(final Context context) {
super(context);
}
public Toolbar(final Context con, AttributeSet attrs) {
super(con,attrs);
setOrientation(HORIZONTAL);
setBackgroundColor(getResources().
getColor(android.R.color.transparent));
LayoutInflater inflater = (LayoutInflater)
con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.navigation, this);
TypedArray a = con.obtainStyledAttributes(attrs,
R.styleable.Toolbar);
String option = a.getString(R.styleable.Toolbar_tab_id);
String resourceId = “com.hlmcorp:id/”+option;
int optionId = getResources().getIdentifier(resourceId,null,null);
TextView currentOption = (TextView) findViewById(optionId);
currentOption.setBackgroundColor(getResources().
getColor(android.R.color.white));
currentOption.setTextColor(getResources().
getColor(android.R.color.black));
currentOption.requestFocus(optionId);
currentOption.setFocusable(false);
currentOption.setClickable(false);
TextView tab1 = (TextView) findViewById(R.id.tab1);
tab1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(con, ebebek.class);
con.startActivity(intent);
}
});
TextView tab2 = (TextView) findViewById(R.id.tab2);
tab2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Intent intent = new Intent(con, Tab2.class);
//con.startActivity(intent);
}
});
TextView tab3 = (TextView) findViewById(R.id.tab3);
tab3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Intent intent = new Intent(con, Tab3.class);
//con.startActivity(intent);
}
});
TextView tab4 = (TextView) findViewById(R.id.tab4);
tab4.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Intent intent = new Intent(con, Tab4.class);
//con.startActivity(intent);
}
});
}
}
[/code]
Büyük ihtimalle R.styleable hatas? alacaks?n?z. Bir önceki yaz?mda belirtti?im gibi android 1.5 üzerinde bu kald?r?ld?. onun için bir resources dosyas?na bir önceki yaz?da belirtti?im ?eyleri ekleyebilirsiniz.
Daha sonra üzerinde çal??aca??n?z activity ‘ye bunu tool olarak eklemelisiniz.
[code lang=”xml”]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_width="match_parent"
android:layout_height="280dp"
android:layout_weight="1.03" />
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Tab 1"
android:gravity="center"/>
android:layout_height="70dip"
app:tab_id="tab1"
/>
[/code]
ekran a?a??daki gibi olacakt?r.