انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
تغیر فونت لیست ویو

تغیر فونت لیست ویو

#1
سلامی دوباره خدمت دوستان گرامی 
من تونستم با این سایت به طراحی برنامم (چندمین برنامم)برسم 
حالا یه سوال دارم چجوری میشه فونت کل آیتم های لیست ویو رو تغییر داد
ممنون میشم جواب بدید
(خواهشنا لینک به این سایت و اون سایت ندید توی این کد ها اموزش بدبد)
یه چیزی یادم رفت بگم چطوری میشه حروف رو داخل لیست ویو وسط چین کرد البته عمودی منظورمه نه وسط صفحه اگ همینم بگید کافیه
کد:
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.TextView;

@SuppressLint("NewApi")
public class MainActivity extends Activity {

@SuppressLint("NewApi")


ListView list;
String[] web = {
"اموزش1",
"Android Ui",
"Java",
"Php",
"Sqllite",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"c#"
} ;
Integer[] imageId = {
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,

};
private DrawerLayout drawerLayout;
private View drawerView;
private View drawerView1;
@SuppressLint("CutPasteId")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ListView tv = (ListView) findViewById(R.id.list);


CustomList adapter = new
CustomList(MainActivity.this, web, imageId);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
switch (position) {
case 0:
    startActivity(new Intent(MainActivity.this, a1.class));

    break;
default:
    break;
}
}

});


//ساخت اکشن بار و نامگذاری اون
ActionBar mActionBar = getActionBar();

//غیر فعال کردن اکشن بار پیش فرض
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);

//معرفی یک Inflater
LayoutInflater mInflater = LayoutInflater.from(this);

//فراخوانی لایه اکشن بار با استفاده از Inflater
View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
mTitleTextView.setText("");






//فعال کردن اکشن بار سفارشی
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);

drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerView = (View) findViewById(R.id.drawer);

ImageButton imageButton = (ImageButton) mCustomView
.findViewById(R.id.imageButton);
imageButton.setOnClickListener(new OnClickListener() {
    

    public void onClick(View arg0) {
        drawerLayout.openDrawer(drawerView);

    }
});



Button btn2=(Button) findViewById(R.id.img);
///در اینجا وظیفه دکمه را بیان می کنیم    
btn2.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
///پس از کلیلک بر روی دکمه به چه صفحه ای برویم
            Intent next= new Intent(MainActivity.this, a1.class );
            next.putExtra("btn", 22);
            startActivity(next);
            
        }
    });

}
}
آدم ها سه دسنه اند :
Explanation موفق - با تلاش - بدون امید Explanation
پاسخ

تغیر فونت لیست ویو

#2
(۱۳۹۵/۰۲/۰۹, ۱۲:۳۷ ب.ظ)hossein5513 نوشته: سلامی دوباره خدمت دوستان گرامی 
من تونستم با این سایت به طراحی برنامم (چندمین برنامم)برسم 
حالا یه سوال دارم چجوری میشه فونت کل آیتم های لیست ویو رو تغییر داد
ممنون میشم جواب بدید
(خواهشنا لینک به این سایت و اون سایت ندید توی این کد ها اموزش بدبد)
یه چیزی یادم رفت بگم چطوری میشه حروف رو داخل لیست ویو وسط چین کرد البته عمودی منظورمه نه وسط صفحه اگ همینم بگید کافیه
کد:
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.TextView;

@SuppressLint("NewApi")
public class MainActivity extends Activity {

@SuppressLint("NewApi")


ListView list;
String[] web = {
"اموزش1",
"Android Ui",
"Java",
"Php",
"Sqllite",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"Html",
"c#"
} ;
Integer[] imageId = {
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,
R.drawable.ic_launcher,

};
private DrawerLayout drawerLayout;
private View drawerView;
private View drawerView1;
@SuppressLint("CutPasteId")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ListView tv = (ListView) findViewById(R.id.list);


CustomList adapter = new
CustomList(MainActivity.this, web, imageId);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
switch (position) {
case 0:
    startActivity(new Intent(MainActivity.this, a1.class));

    break;
default:
    break;
}
}

});


//ساخت اکشن بار و نامگذاری اون
ActionBar mActionBar = getActionBar();

//غیر فعال کردن اکشن بار پیش فرض
mActionBar.setDisplayShowHomeEnabled(false);
mActionBar.setDisplayShowTitleEnabled(false);

//معرفی یک Inflater
LayoutInflater mInflater = LayoutInflater.from(this);

//فراخوانی لایه اکشن بار با استفاده از Inflater
View mCustomView = mInflater.inflate(R.layout.custom_actionbar, null);
TextView mTitleTextView = (TextView) mCustomView.findViewById(R.id.title_text);
mTitleTextView.setText("");






//فعال کردن اکشن بار سفارشی
mActionBar.setCustomView(mCustomView);
mActionBar.setDisplayShowCustomEnabled(true);

drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerView = (View) findViewById(R.id.drawer);

ImageButton imageButton = (ImageButton) mCustomView
.findViewById(R.id.imageButton);
imageButton.setOnClickListener(new OnClickListener() {
    

    public void onClick(View arg0) {
        drawerLayout.openDrawer(drawerView);

    }
});



Button btn2=(Button) findViewById(R.id.img);
///در اینجا وظیفه دکمه را بیان می کنیم    
btn2.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
///پس از کلیلک بر روی دکمه به چه صفحه ای برویم
            Intent next= new Intent(MainActivity.this, a1.class );
            next.putExtra("btn", 22);
            startActivity(next);
            
        }
    });

}
}

سلام دوست عزیز
ابتدا فونتی که مد نظر را دارید داخل پوشه assets قرار دهید (اگر از اندروید استادیو استفاده مکنید این پوشه را بسازید)
شما یک آداپتر برای پر کردن لیستتون ساختید وارد اون بشید
توی سازنده کلاس این کد را وارد کنید
کد:
Typeface customFont = Typeface.createFromAsset(getAssets(),"fonts/yourFontName.ttf");

و اونجایی که دارید ویو میسازید از یک layout استفاده میکنید بعد از اینکه textView  رو fineViewById کردید این کد را وارد کنید
کد:
yourTextView.setTypeFace(customFont);
اوکی میشه!
اگه جواب نداد کد های توی customAdapter رو قرار بدید
پاسخ
 سپاس شده توسط hossein5513

تغیر فونت لیست ویو

#3
ممنون میشه یکم باز تر توضیح بدید
آدم ها سه دسنه اند :
Explanation موفق - با تلاش - بدون امید Explanation
پاسخ

تغیر فونت لیست ویو

#4
میشه یکی کمک  کنه  Huh Huh Huh
آدم ها سه دسنه اند :
Explanation موفق - با تلاش - بدون امید Explanation
پاسخ

تغیر فونت لیست ویو

#5
برای این کار باید از custom adapter یا به اصطلاع adapter شخضی سازی شده استفاده کنید

برای این کار باید ابتدا یک کلاس جدید بسازیر و اون رو از arrayadapter یا baseadapter مشتقم بگیرید یا extend کنید.
بعدش درون این کلاس جدید میتونید هز تغییراتی که میخواید رو برو روی ردیفهای list خودیتون اعمال کنید

در زیر یه نمونه از کلاس گفته شده قرار داده شده میتونید از ازش کمک بگیرید.

کد:
public class ListAdapter extends ArrayAdapter<Item> {

   public ListAdapter(Context context, int textViewResourceId) {
       super(context, textViewResourceId);
   }

   public ListAdapter(Context context, int resource, List<Item> items) {
       super(context, resource, items);
   }

   @Override
   public View getView(int position, View convertView, ViewGroup parent) {

       View v = convertView;

       if (v == null) {
           LayoutInflater vi;
           vi = LayoutInflater.from(getContext());
           v = vi.inflate(R.layout.itemlistrow, null);
       }

       Item p = getItem(position);

       if (p != null) {
           TextView tt1 = (TextView) v.findViewById(R.id.id);
           TextView tt2 = (TextView) v.findViewById(R.id.categoryId);
           TextView tt3 = (TextView) v.findViewById(R.id.description);

           if (tt1 != null) {
               tt1.setText(p.getId());
           }

           if (tt2 != null) {
               tt2.setText(p.getCategory().getId());
           }

           if (tt3 != null) {
               tt3.setText(p.getDescription());
           }
       }

       return v;
   }

}

این هم layout مربوط به ردیف های list شما ( کلاس بالا )
کد پی‌اچ‌پی:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" android:orientation="vertical"
    android:layout_width="fill_parent">

    <TableRow android:layout_width="fill_parent"
              android:id="@+id/TableRow01"
              android:layout_height="wrap_content">

        <TextView android:textColor="#FFFFFF"
                  android:id="@+id/id"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:text="id" android:textStyle="bold" 
                  android:gravity="left"
                  android:layout_weight="1" 
                  android:typeface="monospace"
                  android:height="40sp" />
    </TableRow>

    <TableRow android:layout_height="wrap_content"
              android:layout_width="fill_parent">

        <TextView android:textColor="#FFFFFF" 
                  android:id="@+id/categoryId"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:text="categoryId" 
                  android:layout_weight="1" 
                  android:height="20sp" />

        <TextView android:layout_height="wrap_content"
                  android:layout_width="fill_parent" 
                  android:layout_weight="1"
                  android:textColor="#FFFFFF"
                  android:gravity="right"
                  android:id="@+id/description"
                  android:text="description" 
                  android:height="20sp" />
    </TableRow>

</TableLayout> 
پاسخ
 سپاس شده توسط hossein5513 ، شماره مجازی امارات ، تلگرام ضد فیلتر 2023


پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان