2016-05-05 7 views

答えて

0

は、まず:私たちは、カスタムビューを使用しているため

actionBar.setDisplayShowTitleEnabled(false); 

第二に、falseにタイトルを設定します。最後に

<?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="match_parent" 
    android:background="@android:color/transparent" > 

    <TextView 
     android:id="@+id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_marginLeft="10dp" 
     android:textSize="20dp" 
     android:maxLines="1" 
     android:ellipsize="end" 
     android:text="" /> 

</RelativeLayout> 

titleview.xml作成:

//font file must be in the phone db so you have to create download file code 
//check the code on the bottom part of the download file code. 

    TypeFace font = Typeface.createFromFile("/storage/emulated/0/Android/data/" 
    + BuildConfig.APPLICATION_ID + "/files/" + "font name" + ".ttf"); 

    if(font != null) { 
     LayoutInflater inflator = LayoutInflater.from(this); 
     View v = inflator.inflate(R.layout.titleview, null); 
     TextView titleTv = ((TextView) v.findViewById(R.id.title)); 
     titleTv.setText(title); 
     titleTv.setTypeface(font); 
     actionBar.setCustomView(v); 
    } else { 
     actionBar.setDisplayShowTitleEnabled(true); 
     actionBar.setTitle(" " + title); // Need to add a title 
    } 

DOWNLOADフォントファイルを:私はファイルを雲の中に保存しているので、ダウンロードするためのリンクがあります。

/**downloadFile*/ 
public void downloadFile(){ 
    String DownloadUrl = //url here 
    File file = new File("/storage/emulated/0/Android/data/" + BuildConfig.APPLICATION_ID + "/files/"); 
    File[] list = file.listFiles(); 
    if(list == null || list.length <= 0) { 
     BroadcastReceiver onComplete = new BroadcastReceiver() { 
      @Override 
      public void onReceive(Context context, Intent intent) { 
       try{ 
        showContentFragment(false); 
       } catch (Exception e){ 
       } 
      } 
     }; 

     registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); 
     DownloadManager.Request request = new DownloadManager.Request(Uri.parse(DownloadUrl)); 
     request.setVisibleInDownloadsUi(false); 
     request.setDestinationInExternalFilesDir(this, null, ModelManager.getInstance().getCurrentApp().getRegular_font_name() + ".ttf"); 
     DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); 
     manager.enqueue(request); 
    } else { 
     for (File files : list) { 
      if (!files.getName().equals("font_name" + ".ttf")) { 
       BroadcastReceiver onComplete = new BroadcastReceiver() { 
        @Override 
        public void onReceive(Context context, Intent intent) { 
         try{ 
          showContentFragment(false); 
         } catch (Exception e){ 
         } 
        } 
       }; 

       registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); 
       DownloadManager.Request request = new DownloadManager.Request(Uri.parse(DownloadUrl)); 
       request.setVisibleInDownloadsUi(false); 
       request.setDestinationInExternalFilesDir(this, null, "font_name" + ".ttf"); 
       DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); 
       manager.enqueue(request); 
      } else { 
       showContentFragment(false); 
       break; 
      } 
     } 
    } 
} 
+0

これはあなたの投稿の一部であるはずですか? –

+0

あなたはどういう意味ですか? –

+0

投稿を追加してからすぐに回答を追加しました。私はあなたが誤って答えとしてあなたの投稿のいくつかの追加の詳細を投稿した可能性があるかどうか疑問に思っていた。 –

関連する問題