This question already has answers here:
How to Set a Custom Font in the ActionBar Title?
(17 answers)
Closed 9 years ago.
How can i add custom font(Kulturista _Bold.ttf) to Action bar and change text color to #ffffff without changing min api level 11
see this it might be useful to you
Use the support library you should have backward compatibility. Import the support library into your workspace which can be found in ~/adt-bundle-linux-x86_64-20130729/sdk/extras/android/support/v7/appcompact and use is in your project. And also don't forget to add the support library which can be brought up right clicking into your project and entering Android Tools -> Add Support Library
Using appcompact you will have to extend your activity class with ActionBarActivity. And also using the appcompact you have to make changes in your styles folder. You could refer to this. Do not also forget to update the values-v11 and values-v14 file. Doing all of this will make your application compatible.
P.S. If any error occurs in your appcompact library. Don't panic look at the error logs and open the file that seems to contain the error. Most probably you will have to refresh the file and after that you just fix project properties, and the error goes away.
For custom font, add to assests:
Create a helper class to initialize font:
public class Utils {
public static Typeface fontsStyle;
public static void TypeFaceOne(TextView tv, AssetManager asm){
fontsStyle=Typeface.createFromAsset(asm, "fonts/Roboto-Bold.ttf");
tv.setTypeface(fontsStyle);
}
}
Finally use a custom view for actionbar:
this.getSupportActionBar().setDisplayShowCustomEnabled(true);
this.getSupprotActionBar().setDisplayShowTitleEnabled(false);
LayoutInflater inflator = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.customabview, null);
//customize text
Utils.TypeFaceOne(textview, getAssets());
textview.setTextColor(Color.parseColor("#FFFFFF"));
this.getSupportActionBar().setCustomView(v);
Hope this helps :)
Related
I'm using Material outlined button in Android Studio (material version is 1.4.0).
I wanted to change outline color when button is pressed. so,
binding.activeButton.setOnClickListener{
binding.activeButton.setStrokeColor(Color.parseColor("#FFFFFF"))
}
However, I can't use setStrokeColor method.
It says "Unresolved reference: setStrokeColor"
I still can use app:strokeColor="#color/white" in the XML file, but I can't use setStrokeColor method in an activity file.
What would be the reason ? Is it because of material design version?
Try it:
binding.activeButton.setStrokeColorResource(R.color.back_color_green_btn)
Problem
I want to override a layout file from android namespace, e.g. R.layout.popup_menu_item_layout (which is referenced from code as com.android.internal.R.layout.popup_menu_item_layout). By saying override, I assume declaring an xml file in the project which would be prioritized over the layout that framework owns.
Note, this is just an example layout, so the question concerns to each layout that's present in sdk/platforms/android-XX/data/res/layout directory.
What I've tried
tools:override
There's an undocumented tools:override tag available, which overrides specific resources. See this answer for an example, which overrides values from Design Support Library, not from Android framework.
Applying tools:override="true" to the root tag of the layout won't take effect.
XML layout references - refs.xml
As described in this post, declaring a refs.xml file in /values/ directory with following content:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="layout" name="activity_main">#layout/activity_second</item>
</resources>
will refer to activity_second.xml once activity_main.xml is used. There's an answer that suggests using this technique in order to substitute Snackbar's layout.
This also won't take effect.
Question
Is there any legitimate way to override/substitute a layout file from android package?
I know this is an old question but I also wanted to override a library layout with my own, here's how I did it.
The layout in question was called design_bottom_navigation_item
In refs.xml I added the following:
<resources xmlns:tools="http://schemas.android.com/tools">
<item name="design_bottom_navigation_item" type="layout" tools:override="true">#layout/bottom_navigation_item</item>
</resources>
There are 4 parts to this which I'll explain.
Name: This is the name of the layout you want to override
Type: The type of resource you are trying to override, in this case a layout.
tools:override: This is how you tell Android Studio to override the library layout with your own.
Value: This is where you specify what resource you want to use instead.
You can do this with any resource type this way.
What is that you're trying to do?
If the idea to only replace how the menu-item will look like, you can try the following:
Create a custom MyMenuAdapter extends MenuAdapter
Override the getView method to return the view from your adapter.
You are trying to customise your sdk on the application itself, at runtime.
That's just not how it works.
If you use an SDK on your project(on any technologies), and you need to modify some behavior, you will tweak this SDK and after that, compile your project with this news customized version.
Trying to modify it at runtime is not a good idea.
You will face multiple issues (retro compatibility, security trigger, TREBLE incompatibility , dependency issue, etc)
You have 4 possibilities to do what you want:
Make your own android rom where you will apply your modification
Copy the resources you need to modify on a fake xmlObject with the tag, after the onPostCreate of your application, you will be able to modify the when inflation. You can generalize this behavior and it will simulate an sdk overlay.
Make your own sdk :)
Multi-level reflection, but, no way you succeed with a stable version
Of course, none of this solutions is applicable for a public app.
don't know your issue have fixed or not but simple solution for this is create new layout that is same layout name of framework (in this case is popup_menu_item_layout). Then go to android google source to copy xml content popup_menu_item_layout
So you can custom anything u want. But remember don't change any id of views.
I'm trying to change the checkbox box's color programmatically to a different color than the theme's default. The problem is I was doing something like this:
checkbox.setSupportButtonTintList(ColorStateList);
It works but it seems, according its class documentation, this method has been restricted to be used only by classes from the same package (com.android.support). This is the warning I got from Android Studio:
AppCompatCheckBox.setSupportButtonTintList can only be called from within the same library group (groupId=com.android.support)
Is there a standard/correct way of doing this for all API levels?
Finally, found the answer here from one of the Google guys: https://code.google.com/p/android/issues/detail?id=202235. I was right about not using:
checkbox.setSupportButtonTintList(ColorStateList);
It seems is a private API. Instead, you have to use:
CompoundButtonCompat.setButtonTintList(checkbox, colorStateList);
Based on rylexr answer, you can specify the color in the following way:
CompoundButtonCompat.setButtonTintList(checkboxView, ColorStateList
.valueOf(getResources().getColor(R.color.red)));
chxAll.setButtonTintList(ColorStateList.valueOf(Color.parseColor("#CC0000")));
chxAll is a object of android.widget.CheckBox
replace the hexacolor code for desigred color
The attribute tabsBackgroundColor in tagGroup tag not working on android
<TabGroup tabsBackgroundColor="#a466a3">
and backgroundColor not working too , although it is written in the documentation
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.TabGroup
You'll need to modify your theme file / create a custom android theme to set the appearance of of your tabs.
http://docs.appcelerator.com/platform/latest/#!/guide/Android_Themes
If you read that you'll see how to add and setup a custom theme to override the base theme that Titanium gives you.
The XML property you'll want to modify for the background colour is actionBarTabStyle
A helpful but old tool that you can use to auto generate this is https://jgilfelt.github.io/android-actionbarstylegenerator/
I added the android-support-library-v7-appcompat to my project to support ActionBar from API level 7 above.
It works like a charm on android 4.0+ and also on android 2.3 with a normal Activity that has setContentView in onCreate, but when the activity is loading an Fragment in onCreate the ActionBar gets overlapped with the content of my layout. At all other scenarios the ActionBar works well.
Here is some code:
class AssetsActivity extends ActionBarActivity{
#Override
protected void onCreate(Bundle arg0)
{
super.onCreate(arg0);
OpenLocalFragment assets = OpenLocalFragment.newInstance(index);
assets.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, assets).commit();
}
}
The theme of this activity is set in the manifest to:
#style/Theme.AppCompat
An this is the result on android 2.3 (on 4.0+ the ActionBar shows well)
You can se that the first lisview item is overlaping the ActionBar(White round icon and title "My activity")
It is possible that i found a bug in the support library, it is released only for 2 days now?
Thanks to all.
Edit:
This is now officially fixed and released in the Support Library v19.
As JJD commented below, you can use normally android.R.id.content with appcompat-v7 r.19.0.0 or newer. The home button works too.
With other words: The workaround below is no more needed if you use version 19.0.0 or newer.
I got the answer at code.google.com. i've made a summary from frederic's answer:
For pre ICS devices you must use:
R.id.action_bar_activity_content
instead of
android.R.id.content
R.id.action_bar_activity_content is a new id used in layout for displaying app content, it would appear that it replace android.R.id.content when you use support v7 appcompat ActionBarActivity.
You can use this code to retrieve the correct id of the activity content :
public static int getContentViewCompat() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH ?
android.R.id.content : R.id.action_bar_activity_content;
}
Thanks to frederic
Another alternative if you do not want to modify the source code of android-support-library-v7-appcompat is to add an empty layout in the layout xml file such as:
<LinearLayout
android:id="#+id/content_view"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
and make the fragment call to add to that layout instead:
ft.add(R.id.content_view, mFragment, mTag);
Seems a bit late to contribute but I had the same problem and haven't seen the answer here....
Check your styles.xml file, there might be an xml attribute for overlaying the actionbar set to true ie
true
The whole entry looks something like this
<item name ="actionBarTabTextStyle" > #style/TabTextStyle</item>
<item name = "windowActionBarOverlay">true</item>
If that is the case then just change the value of "windowActionBarOverlay" to false.
Add a extra empty list header with the size of the actionbar. Should be a good workaround.