بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
تغییر رنگ هر عنوان در ویو پیجر (لطفا کمک کنید)
سلام
کسی میدونه چطور در ویو پیجر میشه رنگ هر عنوان را متفاوت نشون داد ؟
مثلا صفحه اول عنوانش قرمز صفحه دوم سبز و ...
میخام از همون اول این زنگی باشن نه وقتی رفتیم داخل هر فرگمنت
public class MainActivity2 extends ActionBarSetup {
private final Handler handler = new Handler();
public static PagerSlidingTabStrip tabs;
private ViewPager pager;
private MyPagerAdapter adapter;
private Drawable oldBackground = null;
private int currentColor = Color.RED;
Context context;
DataSource datasource;
public static MenuActivity menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
G.currentActivity = this;
G.currentActivity_main = this;
setContentView(R.layout.activity_main);
context = this;
datasource = new DataSource(this);
tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
pager = (ViewPager) findViewById(R.id.pager);
adapter = new MyPagerAdapter(getSupportFragmentManager());
tabs.setTextSize(30);
tabs.setDividerColor(Color.parseColor("#F8F8F8"));
tabs.setTextColorResource(R.color.tab_title);// onvane tabha
// tabs.setBackgroundColor(Color.WHITE); // poshte tabha
tabs.setIndicatorColorResource(R.color.tab_color);// navar joda konande
tabs.setUnderlineColorResource(R.color.tab_line);// navar joda konande
tabs.setUnderlineHeight(1);
tabs.setIndicatorHeight(5);
// tabs.setUnderlineHeight(1);
// getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
// getActionBar().setCustomView(R.layout.action_bar);
// getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#f8f8f8")));
// getActionBar().setDisplayShowHomeEnabled(false);
// getActionBar().setDisplayShowCustomEnabled(true);
// getActionBar().setDisplayShowTitleEnabled(false);
// getActionBar().setCustomView(R.layout.action_bar);
// getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#f8f8f8")));
// Toolbar parent = (Toolbar) getActionBar().getCustomView().getParent();
// parent.setContentInsetsAbsolute(0, 0);
// getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#f8f8f8")));
// tabs.setIndicatorColor(R.color.tab_title);// navar joda konande
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.action_bar);
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F8F8F8")));
// actionBar.setBackgroundDrawable(ld);
pager.setAdapter(adapter);
final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0, getResources()
.getDisplayMetrics());
pager.setPageMargin(pageMargin);
tabs.setViewPager(pager);
// pstsTabBackground
Typeface typeface = Typeface.createFromAsset(context.getAssets(), "font/nazanin.ttf");
tabs.setTypeface(typeface, 2);
// changeColor(currentColor);
ImageView img = (ImageView) findViewById(R.id.imgMenu);
// img.setScaleType(ImageView.ScaleType.FIT_CENTER);
menu = new MenuActivity(G.currentActivity);
menu.setBehindOffset(60);
img.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
menu.toggle();
}
});
// setupactionbar();
final ImageView imgSearch = (ImageView) findViewById(R.id.imgSearch);
final EditText edtSearch = (EditText) findViewById(R.id.edtSearch);
final LinearLayout actionLinear = (LinearLayout) findViewById(R.id.actionLinear);
imgSearch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
edtSearch.setVisibility(View.VISIBLE);
actionLinear.setVisibility(View.INVISIBLE);
}
});
edtSearch.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getRawX() >= ((edtSearch.getRight() - edtSearch.getCompoundDrawables()[2].getBounds().width()))) {
// your action here
edtSearch.setVisibility(View.INVISIBLE);
actionLinear.setVisibility(View.VISIBLE);
edtSearch.setText("");
return true;
}
}
return false;
}
});
//search
edtSearch.setImeOptions(EditorInfo.IME_ACTION_DONE);
edtSearch.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {
if (arg1 == EditorInfo.IME_ACTION_DONE) {
doSearch(edtSearch.getText().toString());
return true;
}
return false;
}
});
ImageView img_decorane = (ImageView) findViewById(R.id.img_decorane);
img_decorane.setScaleType(ImageView.ScaleType.FIT_CENTER);
pager.setCurrentItem(3);
}
private void doSearch(String text) {
Intent searchIntent = new Intent(MainActivity2.this, FastSearchActivity.class);
searchIntent.putExtra("text", text);
startActivity(searchIntent);
}//end of doSearch
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.imgMenu:
return true;
}
return super.onOptionsItemSelected(item);
}
private void changeColor(int newColor) {
tabs.setIndicatorColor(newColor);
// change ActionBar color just if an ActionBar is available
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Drawable colorDrawable = new ColorDrawable(newColor);
Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom);
LayerDrawable ld = new LayerDrawable(new Drawable[]{ colorDrawable, bottomDrawable });
if (oldBackground == null) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
ld.setCallback(drawableCallback);
} else {
getSupportActionBar().setBackgroundDrawable(ld);
}
} else {
TransitionDrawable td = new TransitionDrawable(new Drawable[]{ oldBackground, ld });
// workaround for broken ActionBarContainer drawable handling on
// pre-API 17 builds
// https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
td.setCallback(drawableCallback);
} else {
getSupportActionBar().setBackgroundDrawable(td);
}
td.startTransition(200);
}
oldBackground = ld;
// http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setDisplayShowTitleEnabled(true);
}
currentColor = newColor;
}
public void onColorClicked(View v) {
int color = Color.parseColor(v.getTag().toString());
changeColor(color);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("currentColor", currentColor);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
currentColor = savedInstanceState.getInt("currentColor");
changeColor(currentColor);
}
private Drawable.Callback drawableCallback = new Drawable.Callback() {
@Override
public void invalidateDrawable(Drawable who) {
getActionBar().setBackgroundDrawable(who);
}
@Override
public void scheduleDrawable(Drawable who, Runnable what, long when) {
handler.postAtTime(what, when);
}
@Override
public void unscheduleDrawable(Drawable who, Runnable what) {
handler.removeCallbacks(what);
}
};
public class MyPagerAdapter extends FragmentPagerAdapter {
public final String[] TITLES = { " خانــــه2 ", " خانــــه3 ", " خانــــه " };
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public CharSequence getPageTitle(int position) {
return TITLES[position];
}
@Override
public int getCount() {
return TITLES.length;
}
@Override
public Fragment getItem(int position) {
if (position == 0) {
return Fragment_chideman.newInstance(position);
}
if (position == 1) {
return Fragment_Bazar.newInstance(position);
}
if (position == 2) {
return FragmentB.newInstance(position);
}
if (position == 3) {
return FragmentB.newInstance(position);
} else {
return FragmentB.newInstance(position);
}
}
}
}
برای این سوال پاسخی وجود ندارد.
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .