با سلام دوستان. من دارم یه برنامه فارسی اندروید می نویسیم اما ظاهر Title Bar یا همون Action Bar اونو زشت کرده. لطفا راهنمایی کنید چجوری اونو راست چین کنم ؟
با سلام دوستان. من دارم یه برنامه فارسی اندروید می نویسیم اما ظاهر Title Bar یا همون Action Bar اونو زشت کرده. لطفا راهنمایی کنید چجوری اونو راست چین کنم ؟
بایستی سفارشی کنیش
خوب اگه نیازش نداری حذفش کن با
getActionBar().hide();
اگه نیازش داری بگو کد دیگه بگم
ببین این کد کمکت میکنه
private void ActionBar(){ ActionBar mActionBar = getActionBar();
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.action_kala, null);
TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
mTitleTextView.setText(getString(R.string.app_name ));
ImageButton imageButton = (ImageButton) mCustomView.findViewById(R.id.imageButton);
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
imageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(catalog.this,filterprudoct.class);
startActivity(intent);
}
});
}
اینم کد لایوت
<?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="50dp" >
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:background="@null"
android:src="@android:drawable/ic_menu_gallery" />
<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff"
android:textStyle="bold" />
</RelativeLayout>
استفاده :
فراخوانی کد زیر در اکتیویتی های مورد نظر
ActionBar();
اول کد جاوای که در بالا دادم رو در اکتیویتی پیست کن
بعد یک Layout ایجاد کن ( در کدهای جاوا هست action_kala) با نام action_kala که می تونی تغییرش بدی بعد که لایوت رو ساختی در همان اکتیویتی که کد جاوا رو پیست کردی زیر کد
setContentView(R.layout.(*));
بنویس
ActionBar();
همین
ببینید این شخصی سازی اکشن بار هست که توسط یک لایوت که به عنوان اکشن بار طراحی شده و داخلش از یک ImageView و TextView استفاده شده که میتونی مواردی اضافه یا حذف نمایید
قبل از هر کاری
1- یک لایوت جدید بساز و کد لایوت رو داخلش پیست کن و با هرنامی که خواستی ذخیره کن
2- کد جاوا رو در هر اکتیویتی که خواستی اکشن بارش شخصی سازی باشه در متد onCreate زیر setContentView کپی کن اگه اکتیویتی هات زیاد باشه فکر کنم بتونی برای کدهای اکشن بار یک Class از نوع Static بسازی و در بگیه اکتیویتی هات استفاده نمایید
نام فایل لایوت ی که برای اکشن بار ساختی رو در کد جاوا در خط View mCustomView = mInflater.inflate(R.layout.action_kala, null); بجای action_kala قرار بده
کار تمام شد
کدهای جاوا :
ActionBar mActionBar = getActionBar(); mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);
LayoutInflater mInflater = LayoutInflater.from(this);
View mCustomView = mInflater.inflate(R.layout.action_kala, null);
TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
mTitleTextView.setText(getString(R.string.app_name ));
ImageButton imageButton = (ImageButton) mCustomView.findViewById(R.id.imageButton);
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);
imageButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(catalog.this,filterprudoct.class);
startActivity(intent);
}
});
کد لایوت:
<?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="50dp" >
<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
android:background="@null"
android:src="@android:drawable/ic_menu_gallery" />
<TextView
android:id="@+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff"
android:textStyle="bold" />
</RelativeLayout>