[Q]Using colored drawable in setReplacement - Xposed General

Hi, yes im newbie in programming and Im still learning.
I have a question
Im trying a made a module which will be coloring a icon in app
For example
Code:
XResources.setSystemWideReplacement("android", "drawable", "btn_check_holo_light", new XResources.DrawableLoader() {
@Override
public Drawable newDrawable(XResources res, int id) throws Throwable {
Drawable draw = (Drawable) res.getDrawable(R.drawable.abc_btn_check_material);
return draw;
}
});
abc_btn_check_material :
Code:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@drawable/abc_btn_check_to_on_mtrl_015" />
<item android:drawable="@drawable/abc_btn_check_to_on_mtrl_000" />
</selector>
And i want replace a btn_check_holo_light.xml with abc_btn_check_material.xml and color this two .png abc_btn_check_to_on_mtrl_015, abc_btn_check_to_on_mtrl_000 using color picker, Im trying to add a
Code:
draw.setColorFilter(colorint, Mode.MULTIPLY);
(colorin is a color picked from color picker and converted to int)
but this not working, If someone can help me or write a mini-tut how I can do this I'll be very greatfull.
ps. abc_btn_check_to_on_mtrl_015.png and abc_btn_check_to_on_mtrl_000.png are a white images.

Related

[Q] WebView - Please help

Hello. I want to make webview app, but with buttons like in the image that I have created. Back - Refresh - Forvard.
So maybe someone can help, I'm green with it...
Hi there,
So first thing you need to do is grant INTERNET permission to your app by edditing AndroidManifest.xml
For example (I've made all my additions in bold),
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.application.my.webviewtest" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
[B]<uses-permission android:name="android.permission.INTERNET" />[/B]
</manifest>
Then you need to edit your View so that you have a WebView widget and some buttons, i'm just showing a back and forward button here, so in my activity_main.xml I have,
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
[B] <LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<WebView
android:layout_width="match_parent"
android:layout_height="400dp"
android:id="@+id/myWebView"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="64dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="<"
android:id="@+id/backButton"
android:onClick="OnBackButtonClick"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=">"
android:id="@+id/forwardButton"
android:onClick="OnForwardButtonClick"/>
</LinearLayout>
</LinearLayout>[/B]
</RelativeLayout>
You'll notice I've put it in a vertical linearlayout, and then inside of that a horizontal linearlayout to host the buttons, now for the code in MainActivity.java,
Code:
package com.application.my.webviewtest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
[B]import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;[/B]
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
[B] WebView webview = (WebView) this.findViewById(R.id.myWebView);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.google.co.uk");[/B]
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
[B] public void OnBackButtonClick(View view) {
WebView webview = (WebView) this.findViewById(R.id.myWebView);
webview.goBack();
}
public void OnForwardButtonClick(View view) {
WebView webview = (WebView) this.findViewById(R.id.myWebView);
webview.goForward();
}[/B]
}
I've zipped up the app folder of my AndroidStudio project for you
http://npsoftware.s3.amazonaws.com/android/app.zip

Template Navigation Drawer

I created an main activity with the template "navigation drawer activity" in Android Studio. How can I set the nav drawer for every activity?
activity_main.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="schemas.android.com/apk/res/android"
xmlns:app="//schemas.android.com/apk/res-auto"
xmlns:tools="//schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
content_main.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
xmlns:app="://schemas.android.com/apk/res-auto"
xmlns:tools="://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activities.MainActivity"
tools:showIn="@layout/app_bar_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello stranger!"
android:id="@+id/textView3" />
</LinearLayout>
nav_header_main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:weightSum="1">
<ImageView
android:id="@+id/imageView"
android:layout_width="54dp"
android:layout_height="54dp"
android:maxWidth="10dp"
android:maxHeight="1dp"
android:src="@drawable/library"
android:layout_weight="0.24"
android:paddingLeft="0dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="Home Library"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="app" />
</LinearLayout>
Main activity:
Code:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), NewBookActivity.class);
startActivity(intent);
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_book) {
Intent intent = new Intent(this, BookListActivity.class);
startActivity(intent);
}
/*else if (id == R.id.nav_gallery) {
}
*/
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}

[TUTORIAL][ANDROID] How to add touch events to RecyclerView

At first, it probably seems a better choice to use RecyclerViews instead of the ordinary ListViews but one of the issues that people come across is that there are no touch events implemented in RecyclerViews.
While developing Chatto (re-writing from scratch), I came up with a very logical solution for this. If you are you currently using RecyclerViews, you should be familiar with ViewHolders.
Firstly, in your model layout file for the RecyclerView (.xml file), add an id for the layout that you are using. In my layout file, I'm using a RelativeLayout.
Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:paddingBottom="5dp"
android:id="@+id/chatroomListRelativeRow">
Now let's take a look at a snippet from a custom ViewHolder class that I wrote for Chatto.
Code:
public class RoomViewHolder extends RecyclerView.ViewHolder{
private TextView mLblRoomName;
private TextView mLblRoomCounter;
private ImageView mImgRoomType;
private RelativeLayout chatroomListRelativeRow;
public String roomName;
Notice the line private RelativeLayout chatroomListRelativeRow. As you can see, I've created a RelativeLayout object.
Inside the constructor of the ViewHolder class, I've linked the object back to the RelativeLayout in the .xml file.
Code:
chatroomListRelativeRow = RelativeLayout)v.findViewById(R.id.chatroomListRelativeRow);
Now we can use this object to add the onClickListeners and other touch events.
Code:
chatroomListRelativeRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Log.d("RVH",mLblRoomName.getText().toString());
//FragMessagesList fragMessagesList = new FragMessagesList();
roomName = mLblRoomName.getText().toString();
//go to messages
}
});
In the above code, I've attached a OnClickListener to the RelativeLayout. This means when the user clicks on any part of the layout (RecyclerView row), it will perform the specified action.
Now you can try this out for yourself.
As an addition, I've also attached a OnTouchListener to the layout. In this listener, I'm simply changing the colors when user touches the row and when the row is not touched. Now let's see how its done.
In order to obtain the original color of the layout, I've created a Drawable and called the
Code:
.getBackground()
method on the layout.
Code:
final Drawable origColor = chatroomListRelativeRow.getBackground();
Now we can use this to set the color back to the original color/background when the user is not touching on the row.
Code:
chatroomListRelativeRow.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction()==MotionEvent.ACTION_DOWN){
chatroomListRelativeRow.setBackgroundColor(Color.parseColor("#212121"));
}
else{
chatroomListRelativeRow.setBackground(origColor);
}
return false;
}
});
That's all there is to it!

need help buttons

hi,
im totally new to this, been playing around for like 2 days
i want to put buttons on my app, i add the buttons, place them correctly in android studio but when i build apk and install it on my phone
the buttons disappear only one remain top left corner...
how do i place a button and make its position stay?
is there something im missing with the screen resolution or something?
if anyone could give me hint... would be much appreciated
thanks
nate
Could you post your layout xml file so we can see how you declared these buttons?
activity main.xml:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="****"
xmlns:app="****"
xmlns:tools="****"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.thepiratebay.keven.MainActivity"
android:background="@drawable/background">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="51dp"
android:layout_y="47dp"
androidnClick="sound1"
android:text="bonnefete1" />
</AbsoluteLayout>
mainactivity.java:
package org.thepiratebay.keven;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
MediaPlayer sound1;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sound1 = MediaPlayer.create(this, R.raw.a1toutunmot);
}
public void sound1(View view) {
sound1.start();
}
}
i found on google someone saying
To play a sound try this method:
MediaPlayer mp = MediaPlayer.create(YourActivity.this, R.raw.mysound);
mp.setOnCompletionListener(new OnCompletionListener() {
@override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
}
});
mp.start();
This is the best way I found to play a sound in Android. Hope it helps!
not sure where i place this code?
thanks for help
nate
i just want to release mediaplayer when the sound is finished playing

ListView ArrayAdapter doesn't display list items in Navigation Drawer Activity

I have some problems with the list items of a ListView. I've implemented a Navigation Drawer Activity and want to display a simple ListView with some list items. I haven't changed the implementation of the navigation bar yet, just tried to display an activity I've already implemented. So in the automatically generated app_bar_start.xml I just replaced in the <include layout="@layout/activity_main_list" /> section the example activity by my own activity. So far so good, but I figured out that the list items, I want to add by an ArrayAdapter, doesn't appear in the app.
On the other hand, when I implement an string-array in strings.xml and include this items via android:entries in the xml file of my activity, it works fine.
Also when I display my activity directly, so without the Navigation Drawer Activity, everything works fine too.
So does anybody have an idea why it just don't work included in the Navigation Drawer Acitivity?
MainList.java (this is my own written activity):
Code:
public class MainList extends AppCompatActivity {
private ListView mListView;
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_list);
mListView = (ListView) findViewById(R.id.mainlist);
List<String> list = new ArrayList<String>();
list.add("Dies ist ein Test");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
mListView.setAdapter(adapter);
}
}
activity_main_list.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="..."
xmlns:app="..."
xmlns:tools="..."
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_start"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<ListView
android:id="@+id/mainlist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_green_dark"
android:clickable="true"
android:focusable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</android.support.constraint.ConstraintLayout>
StartActivity.java:
Code:
public class StartActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
}
activity_start.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="..."
xmlns:app="..."
xmlns:tools="..."
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_start"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_start"
app:menu="@menu/activity_start_drawer" />
</android.support.v4.widget.DrawerLayout>
app_bar_start.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="..."
xmlns:app="..."
xmlns:tools="..."
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="martinfactory.archibook.StartActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/activity_main_list" />
</android.support.design.widget.CoordinatorLayout>
Problem solved
Okay I've solved the problem, or actually kind of avoided it. I had to change the structure of my files because I have to implement some fragments and after that all the list items are displayed.

Categories

Resources